# Quick Formula Question

#### WorkMC

##### Board Regular
I'm trying to use LastRow = Range("A65536").End(xlUp).Row to replace the 20000 in the formula below. When I do the formula appears in red, obviously I'm missing something can anyone help.

This is the current formula

ActiveCell.FormulaR1C1 = _
"=IF(COUNTIF(R[1]C[-3]:R20000C1,RC[-3]),""x"",VLOOKUP(RC[-3],R2C1:RC[-2],2,0))"

This is how I've tried to adjust it:

ActiveCell.FormulaR1C1 = _
"=IF(COUNTIF(R[1]C[-3]:R"&LastRow&"C1,RC[-3]),""x"",VLOOKUP(RC[-3],R2C1:RC[-2],2,0))"

### Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This is what I usually use to get the LastRow

Dim LastRow As Long
LastRow = Range("A65536").End(xlUp).Row

Normally I then adjust my formulas to include LastRow, but for some reason in my earlier attempt it does not work and I don't understand why?

Try sticking a space or two around the &, VBA can be a bit picky about that.
Code:
``````ActiveCell.FormulaR1C1 = _
"=IF(COUNTIF(R[1]C[-3]:R" & LastRow & "C1,RC[-3]),""x"",VLOOKUP(RC[-3],R2C1:RC[-2],2,0))"``````

Norie, that solved it.

Thanks I could'nt see the wood for the trees.

Replies
26
Views
750
Replies
3
Views
164
Replies
3
Views
257
Replies
4
Views
591
Replies
14
Views
332

### Forum statistics

1,203,127
Messages
6,053,667
Members
444,677
Latest member
LWilliamsAtchristies

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back