HELP needed - VBA

VINTSB

New Member
Joined
Jan 5, 2017
Messages
1
Can anyone help to fix this VBA? i am trying to have the formula below from cell X3 until the last row which have the data for the row.:eek:


Range("X3").Select
LastRow = Range("X3:X" & .Rows.Count).Formula = _
"=VLOOKUP(RC[-22],'User Data File Backup Old.csv'!C2:C23,22,0)"
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Not sure that you do want your last row based on column X as you have posted (it is more usual for the column to be blank when inserting formula and the last row based on another column like column A) but it is what you asked for (except you stated Row rather than Column) so...

Code:
Sub ZZZ()
Range("X3:X" & Range("X" & Rows.Count).End(xlUp).Row).FormulaR1C1 = _
 "=VLOOKUP(RC[-22],'User Data File Backup Old.csv'!C2:C23,22,0)"
End Sub
 
Upvote 0
Code:
Sub insert()
Dim lr As Long
Dim rng As Range

lr = Cells(Rows.Count, 1).End(xlUp).Row
MsgBox (lr)
Set rng = Range("X3:X" & lr)
With rng
.Formula = "=VLOOKUP(RC[-22],'User Data File Backup Old.csv'!C2:C23,22,0)"
End With

End Sub

This should work if you wan to count column one. Else change rows.count to the column u want to count rows from.
 
Upvote 0
Generic method to go to the last row based on whichever is the longest column with values...

Code:
Sub Anycolumn()
Dim lr As Long
lr = Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
    Range("X3:X" & lr).FormulaR1C1 = _
    "=VLOOKUP(RC[-22],'User Data File Backup Old.csv'!C2:C23,22,0)"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,637
Messages
6,125,964
Members
449,276
Latest member
surendra75

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