Using defined names with range.formula property

DaveBlakeMAAT

Board Regular
Joined
Feb 28, 2016
Messages
187
Hi all

I currently have a formula as listed below within my VBA script which all works great, however, when it populates the formula into the cell it inserts the underlying value of the named range instead of referencing the named range. The named range "MinimumIncomeThreshold" is pointing to an individual cell.

This means that the formula is not dynamic!

Code:
Range("M3", LastFormulaCell).Formula = "=IF(B3<" & [COLOR="#FF0000"]Range("MinimumIncomeThreshold")[/COLOR] & ",""Below Threshold"",MATCH(A3,list!$A$2:$A$1048576,0)+1)"

Does anyone know how I can correct this?

ps: I do not want to reference the cell address directly in my VBA code as this will break if someone decides to be "helpful" and insert new rows!!

Regards

Dave
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
Dave

Try this.
Code:
Range("M3", LastFormulaCell).Formula = "=IF(B3<MinimumIncomeThreshold ,""Below Threshold"",MATCH(A3,list!$A$2:$A$1048576,0)+1)"
 

DaveBlakeMAAT

Board Regular
Joined
Feb 28, 2016
Messages
187
Norie

Thanks for your reply however you appear to of accidentally chopped off the end of the formula!
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
Ach, that's the board doing that.

I'll try again.
Code:
Range("M3", LastFormulaCell).Formula = "=IF(B3 < MinimumIncomeThreshold ,""Below Threshold"",MATCH(A3,list!$A$2:$A$1048576,0)+1)"
 

DaveBlakeMAAT

Board Regular
Joined
Feb 28, 2016
Messages
187
Thanks Norie

I am such a muppet at times!!!!

I did try your suggestion originally, but stupidly I was manually changing the wrong cell value when testing.

I appreciate your help.

Regards

Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,123,288
Messages
5,600,742
Members
414,404
Latest member
OKELKEV

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