Macro for copying data from First sheet to all the other sheets

beautify5

New Member
Joined
Oct 27, 2014
Messages
19
Hello Experts,

I want to copy a range (a1:d6) from Sheet1 (Name changes everytime) to to the same cells (a1:d6) of all other sheets in the workbook (the number of sheets changes everytime).

Thanks in advance.:)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try something like this...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] CopyToOtherSheets()

    [COLOR=darkblue]Dim[/COLOR] Wks                 [COLOR=darkblue]As[/COLOR] Worksheet
    [COLOR=darkblue]Dim[/COLOR] wsSource            [COLOR=darkblue]As[/COLOR] Worksheet
    [COLOR=darkblue]Dim[/COLOR] rSource             [COLOR=darkblue]As[/COLOR] Range
    
    [COLOR=darkblue]Set[/COLOR] wsSource = Worksheets(1) [COLOR=green]'first sheet[/COLOR]
    
    [COLOR=darkblue]Set[/COLOR] rSource = wsSource.Range("A1:D6") [COLOR=green]'copy range[/COLOR]
    
    [COLOR=green]'copy to other sheets[/COLOR]
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] Wks [COLOR=darkblue]In[/COLOR] Worksheets
        [COLOR=darkblue]If[/COLOR] Wks.Name <> wsSource.Name [COLOR=darkblue]Then[/COLOR]
            rSource.Copy Wks.Range(rSource.Address)
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] Wks
    
    MsgBox "Completed...", vbInformation
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Upvote 0
Try something like this...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] CopyToOtherSheets()

    [COLOR=darkblue]Dim[/COLOR] Wks                 [COLOR=darkblue]As[/COLOR] Worksheet
    [COLOR=darkblue]Dim[/COLOR] wsSource            [COLOR=darkblue]As[/COLOR] Worksheet
    [COLOR=darkblue]Dim[/COLOR] rSource             [COLOR=darkblue]As[/COLOR] Range
    
    [COLOR=darkblue]Set[/COLOR] wsSource = Worksheets(1) [COLOR=green]'first sheet[/COLOR]
    
    [COLOR=darkblue]Set[/COLOR] rSource = wsSource.Range("A1:D6") [COLOR=green]'copy range[/COLOR]
    
    [COLOR=green]'copy to other sheets[/COLOR]
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] Wks [COLOR=darkblue]In[/COLOR] Worksheets
        [COLOR=darkblue]If[/COLOR] Wks.Name <> wsSource.Name [COLOR=darkblue]Then[/COLOR]
            rSource.Copy Wks.Range(rSource.Address)
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] Wks
    
    MsgBox "Completed...", vbInformation
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!

5 hours i tried and it didn't work, and a help from a Genius solved it in 5 min. Thank you so much bro. :)
 
Upvote 0
You're very welcome! And thanks for the kind words!

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

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