+ Reply to Thread
Results 1 to 4 of 4

Count and name number of unprotected worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    10-03-2012
    Location
    ny
    MS-Off Ver
    Excel 2007
    Posts
    4

    Count and name number of unprotected worksheets

    Hello All,

    For my project, I need some code through which I can count and have a list of unprotected worksheets in a workbook. I tried it but didn't get any sort of result.

    I will appreciate your help friends.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Count and name number of unprotected worksheets

    Hi, tarunpreet,

    maybe something like
    Sub tarunpreet()
    Dim ws As Worksheet
    Dim strMsg As String
    
    For Each ws In ThisWorkbook.Worksheets
      If Not ws.ProtectContents Then
        strMsg = strMsg & ws.Name & vbCrLf
      End If
    Next ws
    MsgBox Left(strMsg, Len(strMsg) - 2)
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    10-03-2012
    Location
    ny
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Count and name number of unprotected worksheets

    Is there any way I can get count in message box and list in another worksheet!

    Thanks for the help
    Last edited by tarunpreet; 10-21-2012 at 09:14 PM.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Count and name number of unprotected worksheets

    Hi, tarunpreet,

    change the name of the worksheet to suit, Row 1 is left for the header in Column A:
    Sub tarunpreet_2()
    Dim ws As Worksheet
    Dim lngUnprot As Long
    
    Const cstrSUM As String = "Summary"
    
    With Sheets(cstrSUM)
      .Range("A2:A" & .Rows.Count).ClearContents
      For Each ws In ThisWorkbook.Worksheets
        If Not ws.ProtectContents Then
          .Cells(.Cells(Rows.Count, "A").End(xlUp).Row + 1, "A").Value = ws.Name
          lngUnprot = lngUnprot + 1
        End If
      Next ws
    End With
    MsgBox "This Workbook contents " & lngUnprot & " worksheets"
    End Sub
    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1