Forum Discussion
Excel VBA - If Sheet Name IsNumeric Loop - False error message
- Aug 24, 2022
Aargh - I should have seen it - my apologies. The line
MsgBox sTemp = "Refreshed Scoring Template and Formulas for the following worksheets"
should be
MsgBox "Refreshed Scoring Template and Formulas"
Or perhaps you wanted something like this:
Sub ClearUserSheets() Dim WBK As Workbook Dim WKS As Worksheet Dim i As Integer Dim sFolder As String Dim sTemp As String 'Close and save other workbooks For Each WBK In Application.Workbooks If Not (WBK Is Application.ThisWorkbook) Then WBK.Close SaveChanges:=True End If Next WBK 'Select Template area to copy to user sheets ThisWorkbook.Worksheets("Template").Activate Range("A9:H19").Copy 'Loop Through User Sheets, hide non user sheets and Paste Refreshed Template For Each WKS In ThisWorkbook.Worksheets If IsNumeric(WKS.Name) Then With WKS .Range("A9:H19").PasteSpecial xlPasteAll sTemp = sTemp & vbCrLf & .Name End With End If Next WKS 'End and notify user of completed tasks/tabs MsgBox "Refreshed Scoring Template and Formulas for the following worksheets:" & sTemp End Sub
I don't see where this code would produce a message box that says "False".
Could you attach a sample workbook (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar? Alternatively, you can attach it to a private message to me. Thanks in advance.
- JoeCavasinAug 24, 2022Brass Contributor
Attaching a dummy copy here. As this copy lays out there will always be several non-numerically named worksheet tabs. In the real world, there will be 3-5 tabs with text names, and upwards of 15-20 numerically named tabs. Any assistance is appreciated, as always!- HansVogelaarAug 24, 2022MVP
Aargh - I should have seen it - my apologies. The line
MsgBox sTemp = "Refreshed Scoring Template and Formulas for the following worksheets"
should be
MsgBox "Refreshed Scoring Template and Formulas"
Or perhaps you wanted something like this:
Sub ClearUserSheets() Dim WBK As Workbook Dim WKS As Worksheet Dim i As Integer Dim sFolder As String Dim sTemp As String 'Close and save other workbooks For Each WBK In Application.Workbooks If Not (WBK Is Application.ThisWorkbook) Then WBK.Close SaveChanges:=True End If Next WBK 'Select Template area to copy to user sheets ThisWorkbook.Worksheets("Template").Activate Range("A9:H19").Copy 'Loop Through User Sheets, hide non user sheets and Paste Refreshed Template For Each WKS In ThisWorkbook.Worksheets If IsNumeric(WKS.Name) Then With WKS .Range("A9:H19").PasteSpecial xlPasteAll sTemp = sTemp & vbCrLf & .Name End With End If Next WKS 'End and notify user of completed tasks/tabs MsgBox "Refreshed Scoring Template and Formulas for the following worksheets:" & sTemp End Sub- JoeCavasinAug 24, 2022Brass Contributor
Just for my info - would it be regarded as best practice any time i'm doing a "For Each" operation, to follow it with the "sTemp = sTemp & vbCrLf & (insert next item here)" as a format for the operation?
I see this on another template i use, but still being green to VBA, pretty sure it was copy and paste for an operation that repeats on each worksheet in the book. seeing that structure in both templates makes me think it's a best practice of sorts...
- JoeCavasinAug 23, 2022Brass ContributorHey Hans! I'll try to dummy one up, but it would be a bit of work. From my troubleshooting it looks like "False" message box pops up when the "If IsNumeric" encounters the worksheets which are actually named by text, and not number. It currently loops through all of the numeric tabs, making the needed updates perfectly, but then after updates throws the "False" pop up.
-Joe