Checking if a worksheet exists
Closed
Josh
-
2 May 2012 à 17:04
aquarelle Posts 7181 Registration date Saturday 7 April 2007 Status Moderator Last seen 14 February 2026 - 3 May 2012 à 12:33
aquarelle Posts 7181 Registration date Saturday 7 April 2007 Status Moderator Last seen 14 February 2026 - 3 May 2012 à 12:33
Related:
- Vba check if worksheet exists
- Vba check if value exists in array - Guide
- Vba add worksheet - Guide
- Radiation check number - Guide
- Vba find - Guide
- Check soft - Download - Finance
3 responses
rizvisa1
Posts
4478
Registration date
Thursday 28 January 2010
Status
Contributor
Last seen
5 May 2022
766
2 May 2012 à 18:00
2 May 2012 à 18:00
refer to the original thread where you discussed this. If you would notice, the sheet name is a variable. So you need to change the variable from hard coded date to use date and use format function
rizvisa1:
Thank you for the direction. I actually figured it out after you pointed me to "hardcoding" the date. Here's what I did.
---------------------------------------------------------------------
Dim shToday As String
Dim wkSheet As Worksheet
Dim Today as Date
Today = Date
shToday = Format(Today, "ddmmmyyyy")
For Each wkSheet In ThisWorkbook.Worksheets
If wkSheet.Name = shToday Then GoTo EndOfCode
Next wkSheet
<code>
EndOfCode:
-----------------------------------------------------------------------
Again, I appreciate the assistance.
Thank you,
Josh
Thank you for the direction. I actually figured it out after you pointed me to "hardcoding" the date. Here's what I did.
---------------------------------------------------------------------
Dim shToday As String
Dim wkSheet As Worksheet
Dim Today as Date
Today = Date
shToday = Format(Today, "ddmmmyyyy")
For Each wkSheet In ThisWorkbook.Worksheets
If wkSheet.Name = shToday Then GoTo EndOfCode
Next wkSheet
<code>
EndOfCode:
-----------------------------------------------------------------------
Again, I appreciate the assistance.
Thank you,
Josh
aquarelle
Posts
7181
Registration date
Saturday 7 April 2007
Status
Moderator
Last seen
14 February 2026
491
3 May 2012 à 12:33
3 May 2012 à 12:33
Hi,
Try and adapt this macro for your case :
Regards
Try and adapt this macro for your case :
Sub test()
Dim x As Worksheet
Dim ShToday As String
ShToday = Format(Now, "ddmmmyyyy")
On Error Resume Next
Set x = Worksheets(ShToday)
If Err <> 0 Then MsgBox "the sheet does not exist" Else MsgBox "the sheet exists"
On Error GoTo 0
End Sub
Regards