• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Clear Previous Sheets

Tech56

Member
Hi,

Can this code be modified to clear before updating so it removes any sheet names if those sheets have been deleted?

Code:
Sub GetWSNames()
Dim ws As String
Dim i As Long

With ActiveSheet

For i = 1 To .Parent.Worksheets.Count

ws = .Parent.Worksheets(i).Name
.Range("A" & i + 1).Value = ws

Next i
End With
End Sub

Thank you
 
See next code
Code:
Option Explicit
Sub GetWSNames()
Dim ws As String
Dim i As Long

    With ActiveSheet
        Range(.Cells(1, "A"), .Cells(Rows.Count, "A").End(3)).Delete
        For i = 1 To .Parent.Worksheets.Count
            ws = .Parent.Worksheets(i).Name
            .Range("A" & i + 1).Value = ws
        Next i
    End With
End Sub
 
Back
Top