close

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:=quot;Do you want to clean sheet2?quot;,buttons:=vbyesno)
if resp = vbyes then
worksheets(quot;sheet2quot;).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(quot;Delete the data in this sheet?quot;, _
vbQuestion vbYesNo, quot;Confirm Deletionquot;)

If iYesNo = vbNo Then GoTo BailOut

strRange = quot;B2:IV65536quot;
Set r = ActiveWorkbook.ActiveSheet.Range(strRange)

r.Clear

BailOut:

Set r = Nothing
Exit Sub

End Sub
================================================== ====
--
Kevin Backmannquot;Micos3quot; wrote:

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

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

It makes exactly what i expected!

Many Thanks

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()