Incrementing vba code variables

zakynthos

Board Regular
Joined
Mar 28, 2011
Messages
169
I have 100 log sheets Logr1 to Logr100 and want to use the code below to navigate between sheets

What would be the code to increase 'Logr1' in one hundred copies of this code in increments of 1?

Sheets("Logr1").Select
Range("v1:ap20").Select
Selection.ClearContents

So that it runs from the above to

Sheets("Logr100").Select
Range("v1:ap20").Select
Selection.ClearContents

This would be particularly useful as I could then adapt it for other changes I wish to make to a large program.

Many thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Code:
Dim n as long
for n = 1 to 100
   Sheets("Logr" & n).Range("v1:ap20").ClearContents
Next n
for example.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top