Repeat macro on different Sheets

mville

New Member
Joined
Nov 3, 2011
Messages
36
Hi,

I want to perform the same macro on different sheets in my workbook. I have 10 sheets for which I want to perform the macro. (Sheet "2007" to Sheet "2016)

This is the code to be executed on every sheet :

Sub SelectName()


Sheets("2007").Select
Range("A" & Cells.Rows.Count).End(xlUp).Select
Range(Cells(Selection.Row, 1), Cells(Selection.Row, 3)).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.Copy
Sheets("BDMV").Select
Range("A" & Cells.Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste


End Sub

How can i do that?

Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You could select all the sheets and do as in a previous thread.


Code:
For each ws In ActiveWindow.SelectedSheets[/COLOR]
[COLOR=#333333]ws.Select[/COLOR]
[COLOR=#333333]Range("A" & Cells.Rows.Count).End(xlUp).Select[/COLOR]
[COLOR=#333333]Range(Cells(Selection.Row, 1), Cells(Selection.Row, 3)).Select[/COLOR]
[COLOR=#333333]Range(Selection, Selection.End(xlUp)).Select[/COLOR]
[COLOR=#333333]Selection.Copy[/COLOR]
[COLOR=#333333]Sheets("BDMV").Select[/COLOR]
[COLOR=#333333]Range("A" & Cells.Rows.Count).End(xlUp).Select[/COLOR]
[COLOR=#333333]ActiveCell.Offset(1, 0).Select[/COLOR]
[COLOR=#333333]ActiveSheet.Paste
[/COLOR]
[COLOR=#333333]Next ws
[/COLOR]
 
Last edited:
Upvote 0
Another option, in addition to what suggested by mrshl9898

Code:
Sub SelectNameV2()
Dim mySh, Sh As String
'
mySh = Array("2007", "2008", "2009", "2010")   '<<< The complete list of your sheet to copy from
'
For Each Sh In mySh
    Sheets(Sh).Cells(Rows.Count, 1).End(xlUp).Range("A1:C1").Copy _
       Sheets("BDMV").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Next Sh
End Sub

Bye
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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