Clear shhet with macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, i have this macro that cleans sheet2 whenever i run the macro.
It works good but i need that row A and line 1 are not erased.
How can i do this?
dim resp as long
resp = msgbox(Prompt:="Do you want to clean sheet2?",buttons:=vbyesno)
if resp = vbyes then
worksheets("sheet2").cells.clearcontents
end if

Thanks
 
The following macro will do what you want:
======================================================
Sub ClearAll()

Dim strRange As String
Dim r As Range
Dim iYesNo As Integer

iYesNo = MsgBox("Delete the data in this sheet?", _
vbQuestion + vbYesNo, "Confirm Deletion")

If iYesNo = vbNo Then GoTo BailOut

strRange = "B2:IV65536"
Set r = ActiveWorkbook.ActiveSheet.Range(strRange)

r.Clear

BailOut:

Set r = Nothing
Exit Sub

End Sub
======================================================
 
Worked just fine, but it clear all the workbook, to clear only sheet2, was
needed to change a little:
Set r = Worksheets("Sheet2").Cells.Range(strRange)

It makes exactly what i expected!

Many Thanks
 
Back
Top