Forum Discussion

JoeCavasin's avatar
JoeCavasin
Brass Contributor
Aug 23, 2022
Solved

Excel VBA - If Sheet Name IsNumeric Loop - False error message

Morning All,   Need some help on a loop process to take action only on sheets in a workbook where the sheet name is numeric.  The number of numerically named sheets will vary month to month based o...
  • HansVogelaar's avatar
    HansVogelaar
    Aug 24, 2022

    JoeCavasin 

    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

Resources