Run Script to all available worksheets

Jacra

New Member
Joined
Jan 13, 2014
Messages
17
Hi Again,

good day.

Sorry for being a noob. I am having a hard time making this script run in all worksheets of a workbook. can you please help me with this. thank you n advance.

code:

Sub Auto_Open()

Range("A20").Value = (ActiveSheet.HPageBreaks.Count + 1) * (ActiveSheet.VPageBreaks.Count + 1)

End Sub


I think I'm missing something here. the intent is to auto run the script upon opening of workbook. it will display the number of printable pages on cell A20 on every worksheet

Thanks again
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try

Code:
Sub Auto_Open()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Range("A20").Value = (ws.HPageBreaks.Count + 1) * (ws.VPageBreaks.Count + 1)
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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