Display sheets count on Message box

     

    Private Sub CommandButton1_Click()
    Dim j As Integer
    j = ThisWorkbook.Sheets.Count
    MsgBox j
    Range("A1").Value = j
    End Sub

     

     

    State about Worksheets.count

     

  • Workshets.count represensts to total sheets count in an excel
  •  

    Write a program to retrieve the worksheets count in excel worksbook:

     

     

     

    Sheets creation: sheet number > sheets count

     

    Private Sub CommandButton1_Click()
    Dim i As Integer
    For i = 1 To 11
    If i > Sheets.Count Then
    Worksheets.Add after:=Sheets(Worksheets.Count)
    End If
    Sheets(i).Name = CStr(MonthName(i, True))
    Next
    End Sub

     

     

     

    Sheets creation: Number of sheets through INPUTBOX

     

    Private Sub CommandButton1_Click()
    Dim max As Integer
    max = Application.InputBox("Enter the number")
    For i = 1 To max
    ThisWorkbook.Worksheets.Add after: Sheets (Sheets.Count)
    ActiveSheet.Name = "day" & i
    Next
    End Sub