Folks, On the attached jpeg is a simple query. How would I code it to copy the formula in B2 down to B6. The number of rows will vary each time the the code is run.
Folks, On the attached jpeg is a simple query. How would I code it to copy the formula in B2 down to B6. The number of rows will vary each time the the code is run.
Maybe
Sub Fill_It() Dim lr As Long lr = Cells(Rows.Count, 1).End(xlUp).Row Range("B2:B" & lr).FillDown End Sub
something like this
Sub ttt() Dim SearchRange As Range Set SearchRange = Range("G1:I12") 'just for example With Range("B2:B" & Cells(Rows.Count, 1).End(xlUp).Row) .FormulaR1C1 = "=VLOOKUP(RC[-1]," & SearchRange.Address(, , xlR1C1) & ",3,0)" End With End Sub
Jolivanes, Thanks that works a treat, simple when you know how.
How does it work. Does the line "lr = Cells(Rows.Count, 1).End(xlUp).Row" Look right down col A to the very bottom to find the last cell with something enetered?
Nilem, Thanks I guess your solution would work as long as the search range you specify would encompass the largest reasonable area you would expect a cell to be entered into.
Last edited by Bob Phillips; 11-20-2015 at 05:35 AM.
Remember To Do the Following....
Use [Code].... [/Code] tags when posting code to the thread.
Mark your thread as Solved if satisfied by using the Thread Tools options.
If posting the same issue to another forum please show the link
Thanks.
So the .End(xlUp) tells it to go to the bottom and return back up to the first occupied cell?
No, the Rows.Count tells it to go to the bottom, the End(xlUp) tells it to then go up until it hits a cell with a value.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
xld, Got it now thanks.