ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Clear shhet with macro (https://www.excelbanter.com/excel-discussion-misc-queries/72728-clear-shhet-macro.html)

Micos3

Clear shhet with macro
 
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

Kevin B

Clear shhet with macro
 
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
================================================== ====
--
Kevin Backmann


"Micos3" wrote:

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


Micos3

Clear shhet with macro
 
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


All times are GMT +1. The time now is 10:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com