Inserting formula into dynamic column with dynamic rows

Topher V

New Member
Joined
Jan 8, 2010
Messages
4
I would like to insert a formula into the next empty column in a sheet and autofill down until Column A is blank. Thoughts?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
=VLOOKUP(A2,Attempts!$A:$B,2,FALSE)

I should probably mention that I'm looking for VBA code to do this.
 
Last edited:
Upvote 0
Try

Code:
Sub InsFmla()
Dim LR As Long, LC As Integer
LR = Cells(Rows.Count, "A").End(xlUp).Row
LC = Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, LC + 1), Cells(LR, LC + 1)).Formula = "=VLOOKUP(A2,Attempts!$A:$B,2,FALSE)"
End Sub
 
Upvote 0
That works except it does not move to a different column once column B is used. Basically, every day I want the data to go into a new column. Is there a way to have the macro search for the next open column?
 
Upvote 0
In that case maybe

Rich (BB code):
Sub InsFmla()
Dim LR As Long, LC As Integer
LR = Cells(Rows.Count, "A").End(xlUp).Row
LC = Cells(2, Columns.Count).End(xlToLeft).Column
Range(Cells(2, LC + 1), Cells(LR, LC + 1)).Formula = "=VLOOKUP(A2,Attempts!$A:$B,2,FALSE)"
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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