VBA code to put the formula in to first empty column of third row

Wafee

Board Regular
Joined
May 27, 2020
Messages
104
Office Version
  1. 2013
Platform
  1. Windows
Can comeone help me with below code.

I have this formula - =IF($A4<> "",VLOOKUP($A4,Pivot!A:AZ,MATCH("Grand Total",Pivot!$A$2:$AO$2,0),0),VLOOKUP($B4,Pivot!A:AZ,MATCH("Grand Total",Pivot!$A$2:$AO$2,0),0)) which needs to be entered in sheet1 of my workbook. it has be enetered in the 3rd row of the first empty column where there there wont be any data(except in first two rows).

for example in my case G column is empty except it will have data in G1 & G2. when code looks for an empty column G will be the first one and the formula needs to be entered in G3.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Rather than enter one formula then copy/drag down, you can put them all in at once.
VBA Code:
Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(Range("B" & Rows.Count).End(xlUp).Row - 2).Formula = _
  "=IF($A4<> """",VLOOKUP($A4,Pivot!A:AZ,MATCH(""Grand Total"",Pivot!$A$2:$AO$2,0),0),VLOOKUP($B4,Pivot!A:AZ,MATCH(""Grand Total"",Pivot!$A$2:$AO$2,0),0))"
Hi peter,

I promise, it would be the last query. rather than finding the which column to fill i have the column (stored in "Fcol") and I want to have the above formula pasted from 4th row of the column. thank you in advance.
 
Upvote 0
i have the column (stored in "Fcol") and I want to have the above formula pasted from 4th row of the column.
That would be like
Rich (BB code):
Cells(4, Fcol).Resize(Range("B" & Rows.Count).End(xlUp).Row - 3).Formula = ......

Or if you wanted to make it easier to amend, declare startrow as Long and use something like this instead.

Rich (BB code):
startrow = 4
Cells(startrow, Fcol).Resize(Range("B" & Rows.Count).End(xlUp).Row - startrow + 1).Formula = ....
 
Upvote 0
Solution
That would be like
Rich (BB code):
Cells(4, Fcol).Resize(Range("B" & Rows.Count).End(xlUp).Row - 3).Formula = ......

Or if you wanted to make it easier to amend, declare startrow as Long and use something like this instead.

Rich (BB code):
startrow = 4
Cells(startrow, Fcol).Resize(Range("B" & Rows.Count).End(xlUp).Row - startrow + 1).Formula = ....
Thak you Peter. ??
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,751
Members
449,335
Latest member
Tanne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top