excel formula to macro/vba

crims0n

New Member
Joined
Aug 18, 2011
Messages
12
Instead of putting this formula in every rows in the column. I would like to put this formula into macro/vba and automatically check and fill the cell. Thanks

=VLOOKUP(F3,Sheet1!C:H,6,FALSE)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I am assuming u are putting formula
*sheet 2
* Range G3:29


Code:
Sub Test()
Sheets("Sheet2").Range("G3:G29").FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet1!C[-4]:C[1],6,FALSE)"
End Sub

Biz
 
Upvote 0
If you want to fill your columns with only the values of VLookup function try code placed below

Code:
Sub fillV()
Dim CellR As Range

Set RangeN1 = ActiveSheet.Range("F3:F6") 'defines the input (value to search for in the first column of the table_array )
Set RangeN2 = Sheets("Sheet1").Range("C:H") ' defines the table_array
Const ColumnI = "G" 'defines the letter of the column in which Vlookup results will be placed

For Each CellR In RangeN1
    n = CellR.Row
    Cells(n, ColumnI).Value = WorksheetFunction.VLookup(CellR.Value, RangeN2, 6, False)
Next
End Sub
 
Upvote 0
oops. Sorry, i provide incomplete information. The formula is in sheet2. And the values in the vlookup are in sheet1. Thanks for your response
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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