VBA using vlookup with variables

%3CLINGO-SUB%20id%3D%22lingo-sub-467780%22%20slang%3D%22en-US%22%3EVBA%20using%20vlookup%20with%20variables%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-467780%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20macro%20that%20I'm%20trying%20to%20use%20vlookup%20in.%26nbsp%3B%20The%20cell%20where%20the%20data%20goes%20changes%20with%20each%20new%20person%20added%20to%20the%20table.%26nbsp%3B%20The%20table%20has%20140%20rows%20and%20starts%20with%20row%2013.%26nbsp%3B%20I%20have%20code%20in%20place%2C%20that%20works%2C%20to%20find%20the%20next%20empty%20row.%3C%2FP%3E%3CP%3EMy%20problem%20is%20when%20using%20vlookup%20in%20this%20macro%20it%20always%20returns%20%22FALSE%22%20as%20the%20answer.%20This%20is%20a%20new%20learning%20curve%20for%20me%3B%20I'm%20sure%20it%20can%20be%20done%2C%20but%20I've%20run%20out%20of%20ideas%20and%20youtube%20videos%20to%20review.%26nbsp%3B%20I'm%20posting%20the%20code%20below%20and%20hope%20there's%20a%20solution.%3C%2FP%3E%3CP%3EThanks%20for%20your%20time%20in%20advance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECode%3A%3C%2FP%3E%3CP%3EThe%20ContRow%20%26amp%3B%20ContCol%20are%20filled%20by%20data%20that%20stored%20in%20cells%20in%20row%2011.%26nbsp%3B%20I'm%20using%20columns%203%20to%206%20in%20row%2011%20to%20store%20the%20needed%20cell%20references.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20ContRow%2C%20ContCol%20As%20Integer%3C%2FP%3E%3CP%3EContRow%20%3D%20.Range(%22C300%22).End(xlUp).Row%20%2B%201%20'%20find%201st%20empty%20row%3CBR%20%2F%3EFor%20ContCol%20%3D%203%20To%206%3CBR%20%2F%3E.Cells(ContRow%2C%20ContCol).Value%20%3D%20.Range(.Cells(11%2C%20ContCol).Value).Value%3CBR%20%2F%3ENext%20ContCol%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'%20the%20Cells%20portion%20of%20the%20line%20works%20fine%20it's%20the%20vlookup%20that%20is%20failing%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E.Cells(ContRow%2C%20ContCol%20%2B%201).Value%20%3D%20ActiveCell.FormulaR1C1%20%3D%20_%3CBR%20%2F%3E%22%3DVLOOKUP(R%5B-17%5DC%5B-2%5D%2CwardDB%2C2%2CFALSE)%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-467780%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
New Contributor

I have a macro that I'm trying to use vlookup in.  The cell where the data goes changes with each new person added to the table.  The table has 140 rows and starts with row 13.  I have code in place, that works, to find the next empty row.

My problem is when using vlookup in this macro it always returns "FALSE" as the answer. This is a new learning curve for me; I'm sure it can be done, but I've run out of ideas and youtube videos to review.  I'm posting the code below and hope there's a solution.

Thanks for your time in advance.

 

 

Code:

The ContRow & ContCol are filled by data that stored in cells in row 11.  I'm using columns 3 to 6 in row 11 to store the needed cell references.

 

Dim ContRow, ContCol As Integer

ContRow = .Range("C300").End(xlUp).Row + 1 ' find 1st empty row
For ContCol = 3 To 6
.Cells(ContRow, ContCol).Value = .Range(.Cells(11, ContCol).Value).Value
Next ContCol

 

' the Cells portion of the line works fine it's the vlookup that is failing


.Cells(ContRow, ContCol + 1).Value = ActiveCell.FormulaR1C1 = _
"=VLOOKUP(R[-17]C[-2],wardDB,2,FALSE)"

 

0 Replies