Use Named Range rather than hard-coded values

detriez

Board Regular
Joined
Sep 13, 2011
Messages
193
Office Version
  1. 365
Platform
  1. Windows
I have two Dynamic Named Ranges I need to use in sub


  • E2 needs to be replaced with Named Range nDataCountry
  • 'Standard Values'!$B$2:$B$251 needs to be replaced with Named Range nCountry

I am looking for values in nDataCounrty that do not exist in nCountry

This working code does not accommodate the expansion of the dynamic named ranges
Code:
    Range("[COLOR=#0000ff]E2:E24[/COLOR]").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=AND([COLOR=#0000ff]E2[/COLOR]<>"""",ISERROR(MATCH([COLOR=#0000ff]E2[/COLOR],[COLOR=#ff8c00]'Standard Values'!$B$2:$B$251[/COLOR],0)))"

I need to do something like this

Code:
    Range("[COLOR=#0000ff]nDataCountry[/COLOR]").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=AND([COLOR=#0000ff]nDataCountry[/COLOR]<>"""",ISERROR(MATCH([COLOR=#0000ff]nDataCountry[/COLOR],[COLOR=#ff8c00]nCountry[/COLOR],0)))"
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Using named Range.
Code:
ActiveWorkbook.Names.Add Name:="nCountry", RefersToR1C1:= _"=Elavon!R2C2:R" & R_ounter & "C2"
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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
Back
Top