Quick Formula Question

WorkMC

Board Regular
Joined
Jul 21, 2005
Messages
88
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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

WorkMC

Board Regular
Joined
Jul 21, 2005
Messages
88
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
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))"
 

WorkMC

Board Regular
Joined
Jul 21, 2005
Messages
88
Norie, that solved it.

Thanks I could'nt see the wood for the trees.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,812
Messages
5,833,801
Members
430,233
Latest member
cbutts

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Top