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

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

  •  11-06-2023
  •  | 
  •  

Frage

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.

War es hilfreich?

Lösung

This was acknowledged as a solution in the comments:

Range("Q2", "Q" & CellNumber).FormulaR1C1 = "=VLOOKUP(RC[-3],R2C16:R" & CellNumber & "C16,1,FALSE)"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top