Repeating instructions in a Macro.

A

Art MacNeil

Hello all,

I have a Macro that clears any data on different 31 tabs and, due to my
lack of knowledge, I do this one tab at a time. The 31 tabs represent the
maximum possible days in a month. Here's a sample of my Macro:


'======================================================================================================================

' Clear the data on tab 1.
Windows("Revenue Tracker.xls").Activate
Sheets("1").Select
Range("B4:O126").Select
Selection.ClearContents
Range("E4").Select


'----------------------------------------------------------------------------------------------------------------------


' Clear the data on tab 2.
Windows("Revenue Tracker.xls").Activate
Sheets("2").Select
Range("B4:O126").Select
Selection.ClearContents
Range("E4").Select


'----------------------------------------------------------------------------------------------------------------------


I repeat this for every day of the month.


Is there a better way to do this?


Thank you,

Art.
 
L

Leo Heuser

Art MacNeil said:
Hello all,

I have a Macro that clears any data on different 31 tabs and, due to my
lack of knowledge, I do this one tab at a time. The 31 tabs represent the
maximum possible days in a month. Here's a sample of my Macro:


'======================================================================================================================

' Clear the data on tab 1.
Windows("Revenue Tracker.xls").Activate
Sheets("1").Select
Range("B4:O126").Select
Selection.ClearContents
Range("E4").Select


'----------------------------------------------------------------------------------------------------------------------


' Clear the data on tab 2.
Windows("Revenue Tracker.xls").Activate
Sheets("2").Select
Range("B4:O126").Select
Selection.ClearContents
Range("E4").Select


'----------------------------------------------------------------------------------------------------------------------


I repeat this for every day of the month.


Is there a better way to do this?


Thank you,

Art.

Hi Art

Here is a shorter version:


Sub ClearTabs()
Dim Counter As Long

Windows("Revenue Tracker.xls").Activate

Application.ScreenUpdating = False

For Counter = 1 To 31
Sheets(CStr(Counter)).Select
Range("B4:O126").ClearContents
Range("E4").Select
Next Counter

Application.ScreenUpdating = True

End Sub
 

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