Ask Your Question
1

What is the method of incorporating a dynamic VLOOKUP into FormulaR1C1 using VBA?

asked 2022-05-26 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-14 04:00:00 +0000

nofretete gravatar image

To incorporate a dynamic VLOOKUP into FormulaR1C1 using VBA, follow these steps:

  1. Define the range of the lookup table and the lookup value cell. For example:
Dim lookupTable As Range
Set lookupTable = Range("A1:B10")

Dim lookupValue As Range
Set lookupValue = Range("C1")
  1. Use the MATCH function to find the row number of the lookup value in the first column of the lookup table. For example:
Dim rowNumber As Long
rowNumber = Application.WorksheetFunction.Match(lookupValue.Value, lookupTable.Columns(1), 0)
  1. Construct the VLOOKUP formula using the row number as the index number argument. For example:
Dim vlookupFormula As String
vlookupFormula = "=VLOOKUP(" & lookupValue.Address(False, False) & "," & lookupTable.Address(False, False) & ",2,FALSE)"
  1. Set the formula of the desired cell using FormulaR1C1. For example:
Range("D1").FormulaR1C1 = vlookupFormula
  1. Optionally, convert the formula to static values. For example:
Range("D1").Value = Range("D1").Value

By following these steps, you can dynamically incorporate a VLOOKUP formula into FormulaR1C1 using VBA.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-26 11:00:00 +0000

Seen: 9 times

Last updated: Feb 14 '22