Inserting VLOOKUP into spreadsheet using VBA but having table array length adjustable

StackOverflow https://stackoverflow.com/questions/22262948

  •  11-06-2023
  •  | 
  •  

문제

Let me preface by saying I'm very new to VBA and understand there could be easier, cleaner ways to go about this, but here we go:

I have this equation:

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],R2C16:R188C16,1,FALSE)"
Selection.AutoFill Destination:=Range("Q2", "Q" & CellNumber), Type:=xlFillDefault   

It inserts A VLOOKUP equation and compares a column 3 columns over to a table array. It then autofills down to the CellNumber variable length.

The problem is that I want the table array length to be adjustable and use CellNumber in the VLOOKUP equation so that it changes accordingly.

But... I'm having no luck making it work...

Any help would be awesome.

도움이 되었습니까?

해결책

This was acknowledged as a solution in the comments:

Range("Q2", "Q" & CellNumber).FormulaR1C1 = "=VLOOKUP(RC[-3],R2C16:R" & CellNumber & "C16,1,FALSE)"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top