stop loop if prev sheet does not exist

G

Guest

Hi,
How do I stop following loop if prev sheet does not exist? It should still
make

Application.DisplayAlerts = true

??
T
----------------------
Application.DisplayAlerts = False
x = 6
Do While Cells(x, 2).Value <> ""


Sheets("makron").Activate
ActiveSheet.Previous.Select
ActiveSheet.Delete
x = x + 1

Loop
 
N

NickHK

Something like this:

Private Sub CommandButton1_Click()
Dim RowCount As Long
Dim i As Long

With Range("rngStart")
RowCount = .End(xlDown).Row - 1 - .Row
End With
With Worksheets("makron")
If RowCount > .Index - 1 Then
MsgBox "Not enough sheets"
Exit Sub
End If
Application.DisplayAlerts = False
For i = 1 To RowCount
Worksheets(.Index - 1).Delete
Next
Application.DisplayAlerts = True
End With
End Sub

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top