-
Solved: Using Variable Col_Index with VLOOKUP
Hi,
I'm having problems displaying the value of the variable X in the VLOOKUP function. After executing the code, the letter "X" appears in the VLOOKUP forumla instead of the actual value of X.
I'm also having problems with the 'Sheet1'!A:Z portion of the formula. I want the table_array to be from columns A to Z, but after executing the macro, the formula turns out to be 'Sheet1'!AZ).
[VBA]
Sub Macro1()
'
' Macro1 Macro
'
Range("I22").Select
Dim X As Long
Dim Row As Long, Col As Long
X = 2
Row = 22
Col = 3
Do Until Col > 7
Cells(Row, Col).Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(""Test"", 'Sheet1'!A:Z, X, FALSE)"
Col = Col + 1
X = X + 1
Loop
'
End Sub[/VBA]
-
You'll have to take the X out of the quotes.
"=VLOOKUP(""Test"", 'Sheet1'!A:Z, X, FALSE)"
"=VLOOKUP(""Test"", 'Sheet1'!A:Z, " & X & ", FALSE)"
-
Thanks, it's working. SOLVED
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules