Looping Macro

Stringt

New Member
Joined
Feb 18, 2002
Messages
35
I have a simple macro (cut, copy, paste etc) that I want to run on every sheet of my workbook, without having to go to each sheet and run it each time.

How do I get a macro to run it through every sheet?
This message was edited by Stringt on 2002-05-02 02:48
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Does this help? Insert this in your macro:

Dim sht As Worksheet
For Each sht In ThisWorkbook.Sheets
'Your copy paste code
Next sht
 
Upvote 0
Hi Stringt. :)

Why dont you just copy the macro into your personal.xls folder and have excel open it everytime you open a new workbook.If you dont know where to place this email me at garethl@ij.co.za
:cool:
 
Upvote 0
This code does not seem to work. It just does the current sheet you are in then stops... any ideas?
 
Upvote 0
Try a couple other options, depending maybe on what you are trying to do:

''''''''''''''''
for x = 1 to sheets.count
sheets(x).Select
'Your code
next x
''''''''''''''''

Or this, posted on this board sometime ago:

ShCount = Application.Sheets.Count
Sheets(1).Select
For i = 1 To ShCount
'Your code
If i = ShCount Then
End
ActiveSheet.Next.Select
End If
Next i


Any help?
 
Upvote 0
Stringt

You haven't posted your code but, if it refers to any the first sheet or any range name on that sheet, the code will not loop successfully.

If it does refer to, say, Sheet1 as the object, change it to sh to pick up the current sheet instead.

e.g. instead of Worksheets("Sheet1").Range("a1").copy

use

sh.Range("a1").copy

Not very good code, but I hope you'll get what I mean.

Any help?

Regards

Robb__
 
Upvote 0
it doesn't seem to recognise the sheets - do i need to replace x's with my sheet names or what?
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,030
Members
448,940
Latest member
mdusw

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