Checking if a worksheet exists
Closed
Josh
-
May 2, 2012 at 05:04 PM
aquarelle Posts 7141 Registration date Saturday April 7, 2007 Status Moderator Last seen December 19, 2024 - May 3, 2012 at 12:33 PM
aquarelle Posts 7141 Registration date Saturday April 7, 2007 Status Moderator Last seen December 19, 2024 - May 3, 2012 at 12:33 PM
Related:
- Checking if a worksheet exists
- Vba check if value exists in array - Guide
- Transfer data from one excel worksheet to another automatically - Guide
- Maximum active checking torrents - Guide
- How to check if someone is spying on my whatsapp - Guide
- Cannot start virus checking program idm - Guide
3 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
May 2, 2012 at 06:00 PM
May 2, 2012 at 06:00 PM
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
7141
Registration date
Saturday April 7, 2007
Status
Moderator
Last seen
December 19, 2024
491
May 3, 2012 at 12:33 PM
May 3, 2012 at 12:33 PM
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