VBA not finding named ranges

Jimij

New Member
Joined
Dec 7, 2022
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
Hi, this is my first post and I really hope someone can help me out. My workbook has a number of sheets, each with a WorkBook Level Named Range. The following formula on Sheet2 accesses data from the named ranges on Sheet4 (LOData) and Sheet5 (SLOData) and does what it is supposed to do when typed directly into the target cell on Sheet2:

=IF(D2="",SUM(HLOOKUP(B2,LOData,14,FALSE),HLOOKUP(B2,LOData,15,FALSE)),SUM(HLOOKUP(D2,SLOData,11,FALSE),HLOOKUP(D2,SLOData,12,FALSE)))

however when I try to use VBA to insert the formula, I get an error message that an Object has not been defined. I have tried defining LOData and SLOData as Ranges and Names and even setting the ranges, without success. MyFormula is defined as a String

My appreciation in advance.
 

Attachments

  • VBA Code for forum post.PNG
    VBA Code for forum post.PNG
    30.3 KB · Views: 11

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Welcome to the Forum!

You need to double up any quotation marks inside other quotation marks:

Rich (BB code):
MyFormula = "=IF(D2="""",SUM(HLOOKUP(B2,LOData,14,FALSE),HLOOKUP(B2,LOData,15,FALSE)),SUM(HLOOKUP(D2,SLOData,11,FALSE),HLOOKUP(D2,SLOData,12,FALSE)))"
 
Upvote 0
Solution
Hi Stephen, Thanks for the prompt response - works like a charm. Extremely grateful for the advice. Best wishes to you and family for the Festive Season.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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