PDA

View Full Version : How to use variable column number in vba



Arindam_Bag
06-22-2012, 11:13 PM
Hi Experts,

I want to use variable column number in time of vlookup using VBA.

My code is
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,'[MS_Cellwise_NBH_raw kpi_March.xls]TCH Traffic'!C1:C256,a,0)"

Where a is variable.

But it is showing syntax error.

Please help.

Thanks in Advance.

Arindam Bag
India

VoG
06-23-2012, 02:36 AM
Maybe



ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,'[MS_Cellwise_NBH_raw kpi_March.xls]TCH Traffic'!C1:C256," & a & ",0)"


but you are only looking in one column (C).

bolekblues
06-27-2012, 01:07 AM
Yes, you are using only one column in the vlookup range... Either extend the range to sth like C:G, otherwise you will always get error if a is greater than 1 as this will exceed the function range