1
Dim LastRowC As Long
Dim LastRowE As Long
Dim Deelnemernr As Long
    LastRowC = Range("C1048576").End(xlUp).Row + 1
    Deelnemernr = Cells(LastRowC, 3).Offset(0, 4).Select

I can manage to select the variable cell which I want to use in my formula below. So the code above works.

LastRowE = Range("E1048576").End(xlUp).Row + 1
Cells(LastRowE, 5).Formula = "=Index(E:E,Match(Deelnemernr,G:G,0))"

What I cannot seem to do is use the variable declared above as Deelnemernr in my Match formula. When I use a fixed cell (for example G12) in stead of Deelnemernr the formula does work. Can anyone tell my how the refer to a declared variable in a formula?

1 Answer 1

2

You need to get the Deelnemernr variable outside the double quotes ".

Also, there's no need to use Select here :

Deelnemernr = Cells(LastRowC, 3).Offset(0, 4).Select

just get the value of that cell by:

Deelnemernr = Cells(LastRowC, 3).Offset(0, 4).Value

Try the code below:

LastRowC = Range("C1048576").End(xlUp).Row + 1
Deelnemernr = Cells(LastRowC, 3).Offset(0, 4).Value

LastRowE = Range("E1048576").End(xlUp).Row + 1
Cells(LastRowE, 5).Formula = "=Index(E:E,Match(" & Deelnemernr & ",G:G,0))"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.