I want to delete all sheets (Sheet1 to Sheet6) in my workbook. What I have made, is that I have used userform, and by the click on the button "delete data" I want to delete all data on the mentioned sheets. My code so far..
Private Sub CommandButton4_Click()
Unload Me
Dim ws As Worksheets
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each ws In Worksheets
If MsgBox("This command will delete all data?", vbYesNo) = vbNo Then UserForm1.Show Else ws.Delete
End If
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
UserForm1.Show
End Sub
This one does not work. I am novice with VBA and this loop is too way complicated for me. Any ideas how could I do that? Thanks
Just something like
For Each ws In ActiveWorkbook.Sheets
ws.UsedRange.ClearContents
Next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.