leatherhen99
New Member
- Joined
- Dec 17, 2019
- Messages
- 27
- Office Version
- 365
- Platform
- Windows
Good Day,
I have read through so many posts and I'm not finding the issue that I'm struggling to solve.
I am trying to include logic where my macro will stop if there is any missing data... The user, prior to running the macro, needs to move a sheet into the macro-enabled template. The sheet name is in the following format: "LockedMeterStateYYYYMMDDHHMMSS"... So I can't tell it to look for a specific name. I'm able to get this code to work to activate the sheet:
But if the sheet's not there... I want to alert the user to add the sheet so it doesn't wreak havoc on the final output...
What I'd like to be able to do is add an ELSE statement so that if that sheet doesn't exist, it will give a messagebox stating the tab isn't there, add the sheet, and restart the macro... So I've used other threads to create this:
Unfortunately, it doesn't work This code always runs straight thru to the Else statement and exits the sub... it doesn't check anything but the current sheet. I'm certainly not saying it's not a user error, but I've been pondering over this for a few days and I'm at a loss. Any help would be greatly appreciated! Thanks again!
I have read through so many posts and I'm not finding the issue that I'm struggling to solve.
I am trying to include logic where my macro will stop if there is any missing data... The user, prior to running the macro, needs to move a sheet into the macro-enabled template. The sheet name is in the following format: "LockedMeterStateYYYYMMDDHHMMSS"... So I can't tell it to look for a specific name. I'm able to get this code to work to activate the sheet:
VBA Code:
For Each ws In Worksheets
If InStr(1, ws.Name, "LockedMeterState202", vbTextCompare) Then
ws.Activate
End If
Next
But if the sheet's not there... I want to alert the user to add the sheet so it doesn't wreak havoc on the final output...
What I'd like to be able to do is add an ELSE statement so that if that sheet doesn't exist, it will give a messagebox stating the tab isn't there, add the sheet, and restart the macro... So I've used other threads to create this:
Excel Formula:
For Each ws In Worksheets
If InStr(1, ws.Name, "LockedMeterState202", vbTextCompare) Then
ws.Activate
Else
MsgBox "The daily Locked Meter State tab is not in workbook. Please update the file and restart the macro."
Exit Sub
End If
Next
Unfortunately, it doesn't work This code always runs straight thru to the Else statement and exits the sub... it doesn't check anything but the current sheet. I'm certainly not saying it's not a user error, but I've been pondering over this for a few days and I'm at a loss. Any help would be greatly appreciated! Thanks again!