Conflicting code in vba. Macro not returning proper results.

S Oberlander

Board Regular
Joined
Nov 25, 2020
Messages
147
Office Version
  1. 365
Platform
  1. Windows
My macro checks for the existence of two sheets usingIf Not Evaluate
The first sheet I'm checking for is returning the same result regardless if the sheet exists or not!
I tried triple checking the spelling. I tried running it from that sheet and from a different sheet... its still returning that the sheet is missing even though it actually is there.
see my code below:
VBA Code:
Sub Check4sheets()

    If Not Evaluate("isref(Gateway report!A1)") Then      
      MsgBox "Gateway report is missing" 'I'm getting this message even when the sheet is there
    End If
    
   If Not Evaluate("isref(Pivot!A1)") Then
      MsgBox "Pivot is missing"
   End If
    
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
And now? Notice the single quotes

VBA Code:
Sub Check4sheets()
 If Not Evaluate("isref('Gateway report'!A1)") Then
    MsgBox "Gateway report is missing"
 End If
    
 If Not Evaluate("isref('Pivot'!A1)") Then
    MsgBox "Pivot is missing"
 End If
End Sub
 
Upvote 0
Solution
Thanks!
My guess is that the problem is the space in the sheet named gateway report
 
Upvote 0
Tip:

Always use single quotations in sheetreferences. When the sheetnames do not have spaces, it will also work then
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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