Hello,
I am using vlookup to return values in each column and I try to have a VBA set-up.
Currently with below VBA, I need to change "E" and 2 in each column.
e.g) I want to return values in column E and the column index in another sheet is 2. Next column, I change column "F" and the column index in another sheet is 3. Next, column "G" and column index 4.......
Is there a way to repeat it using VBA?
authorWs.Range("E" & x).Value = Application.WorksheetFunction.vlookup( _
authorWs.Range("A" & x).Value, dataRng, 2, False)
I am using vlookup to return values in each column and I try to have a VBA set-up.
Currently with below VBA, I need to change "E" and 2 in each column.
e.g) I want to return values in column E and the column index in another sheet is 2. Next column, I change column "F" and the column index in another sheet is 3. Next, column "G" and column index 4.......
Is there a way to repeat it using VBA?
authorWs.Range("E" & x).Value = Application.WorksheetFunction.vlookup( _
authorWs.Range("A" & x).Value, dataRng, 2, False)
VBA Code:
Sub Vlookup_Entire_Sheet()
Dim authorWs As Worksheet, detailsWs As Worksheet
Dim authorsLastRow As Long, detailsLastRow As Long, x As Long
Dim dataRng As Range
Set authorWs = ThisWorkbook.Worksheets("Entire At once")
Set detailsWs = ThisWorkbook.Worksheets("Details")
authorsLastRow = authorWs.Range("A" & Rows.Count).End(xlUp).Row
detailsLastRow = detailsWs.Range("A" & Rows.Count).End(xlUp).Row
Set dataRng = detailsWs.Range("A3:CI" & detailsLastRow)
For x = 2 To authorsLastRow
On Error Resume Next
authorWs.Range("E" & x).Value = Application.WorksheetFunction.vlookup( _
authorWs.Range("A" & x).Value, dataRng, 2, False)
Next x
End Sub