vba - Vlookup help with Resize

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
983
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,


In Column A I have Emp ID, and next columns infront of it are Login hrs details
I am using multiple vlookup for getting result.just changing Column no.


Can we shorten this code by using resize in data, or any other method to achieve this Task.


Dim dwbk As Workbook
Set dwbk = Workbooks.Open(Mac.Range("b5").Value)


Dim lr As Long
lr = dwbk.Worksheets(1).Range("A1").CurrentRegion.Rows.Count


With ThisWorkbook.Sheets(2)
.Range("b2:b" & lr).FormulaR1C1 = "=VLOOKUP(RC1,'[" & dwbk.Name & "]Login Hrs'!R1C1:R" & lr & "C10,2,0)"
.Range("C2:C" & lr).FormulaR1C1 = "=VLOOKUP(RC1,'[" & dwbk.Name & "]Login Hrs'!R1C1:R" & lr & "C10,3,0)"
.Range("d2:d" & lr).FormulaR1C1 = "=VLOOKUP(RC1,'[" & dwbk.Name & "]Login Hrs'!R1C1:R" & lr & "C10,4,0)"
.Range("e2:e" & lr).FormulaR1C1 = "=VLOOKUP(RC1,'[" & dwbk.Name & "]Login Hrs'!R1C1:R" & lr & "C10,5,0)"
.Range("f2:f" & lr).FormulaR1C1 = "=VLOOKUP(RC1,'[" & dwbk.Name & "]Login Hrs'!R1C1:R" & lr & "C10,6,0)"
.Range("g2:g" & lr).FormulaR1C1 ...........and so on ... till .Range("m2:m" & lr)
End With

Thanks in advance

Regards
mg
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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