当前位置:网站首页>Excel VBA: realize automatic drop-down filling formula to the last line
Excel VBA: realize automatic drop-down filling formula to the last line
2022-07-26 05:03:00 【Avasla】
Problem scenario :
As shown below , Need basis B Column “ project ” Content , lookup G-H In the column , Whether each item belongs to expenditure or income , Then match and fill D In the column .
PS: Here through if() Function to identify the amount of positive and negative output expenditure / income . This method is not considered in this paper , Mainly through the case study VBA Implementation method .
Xlookup + Auto fill formula
Ideas : First , stay D2 The cells are filled with the corresponding Xlookup The formula (vlookup Can also be , But the upgraded version is more recommended Xlookup); Through VBA Realize the function of automatically filling formulas from the drop-down .
Be careful : VBA Auto fill needs to specify the end position , So we need to find “C” Column (AB Columns can also be ) Last line , Use Cells(Rows.Count, "C").End(xlUp).Row
Sub autofill()
Application.ScreenUpdating = False ' Prevent screen jitter when macros are running
Sheets("Sheet1").Select ' choice Sheet1
Range("D2").Select ' choice D2 First cell with formula
' Run the auto fill function on the selected cells , Range is from D2 To D Last row of column ,( The reference here is C Last row position of column )
Selection.autofill Destination:=Sheets("Sheet1").Range("D2:D" & Sheets("Sheet1").Cells(Rows.Count, "C").End(xlUp).Row)
End Sub
Results after operation :
D The columns are automatically filled with the corresponding Xlookup The formula 
边栏推荐
- Sliding window -- leetcode solution
- 未来大气污染变化模拟
- [mathematical modeling] basic knowledge of MATLAB
- @Principle of Autowired annotation
- MODFLOW Flex、GMS、FEFLOW、HYDRUS实践应用
- List转换为tree-项目真实使用
- Switch to router technology: OSPF single zone configuration, OSPF multi zone and end zone
- Ggjj, do you have a look at this problem? Does caching cause cross domain problems?
- Add and modify the verification logic, and use -validation- to complete the group verification
- IEC61131 数据类型与 C#数据类型的对应
猜你喜欢

MODFLOW Flex、GMS、FEFLOW、HYDRUS实践应用

9 best project set management tools

Alibaba three sides: how to solve the problems of MQ message loss, duplication and backlog?

AXI协议(4):AXI通道上的信号

Several maturity levels of using MES management system

Alibaba cloud industrial vision intelligent engineer ACP certification - Preparation

Learn to map with nature medicine -- complex heat map

IEC61131 数据类型与 C#数据类型的对应

What is the real HTAP? (1) Background article

columns in GROUP BY clause; this is incompatible with sql_ mode=only_ full_ group_ By mysql8.0 solution
随机推荐
Batch convert ppm format pictures to JPG format
Stm32fsmc extended SRAM
Redis解决库存超卖问题
Customer service relationship management based on SQL net enterprise messenger enterprise communications
一次线上事故,我顿悟了异步的精髓
CountLaunch Demo的测试
MySQL基础学习
Learn to map with nature medicine -- complex heat map
What points should be paid attention to in the selection of project management system?
地球系统模式(CESM)实践技术
JVM第五讲:纵横数据如何应对洪峰推送
[wp][gwctf 2019] boring lottery
基于通用优化软件GAMS的数学建模和优化分析
[Luogu] p3919 [template] persistent segment tree 1 (persistent array)
Correspondence between IEC61131 data type and C data type
滑动窗口——leetcode题解
C language - pointer one touch ※
注解@Autowired如何自动装配
What are the well-known to-do apps at home and abroad
The importance of supporting horizontal expansion of time series database