VBA code to copy data from one worksheet to many

dlamle

New Member
Joined
Jul 2, 2015
Messages
38
I need a code to complete this objective:

IF sheet count > 16 THEN copy data (range A1:L50) from a sheet named "Multiple" and paste into each worksheet until the last active worksheet has been populated.


Any help is greatly appreciated, thank you
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
To clarify ...... Do you want to copy the range only if you have more than 16 sheets in your workbook and if so, copy the range to all sheets?
 
Upvote 0
Code:
Sub test()
Dim shtMultiple As Worksheet
Dim counter As Long 'Generic counter


    If ThisWorkbook.Sheets.Count > 16 Then
        'Do
        On Error Resume Next
        Set shtMultiple = ThisWorkbook.Sheets("Multiple")
        On Error GoTo 0
        
        If shtMultiple Is Nothing Then
            MsgBox "Error. Sheet DNE."
            Exit Sub
        End If
        
        counter = 1 'first sheet
        Do
            If ThisWorkbook.Sheets(counter).Name <> shtMultiple.Name Then
                ThisWorkbook.Sheets(counter).Range("A1:L50").Value = _
                    shtMultiple.Range("A1:L50").Value
            End If
            
            counter = counter + 1
        Loop While counter <= ThisWorkbook.Sheets.Count
        
    End If
    


End Sub
 
Upvote 0
Try this.

Code:
    If Application.Sheets.Count > 16 Then
    Sheets("Sheet1").Select
        Range("A1:L50").Select
    Selection.Copy
    
    Do Until ActiveSheet.Next Is Nothing
        ActiveSheet.Next.Select
        ActiveSheet.Paste
    Loop
    
    End If
 
Upvote 0
Actually, its 15 (my bad), but yes! only copy the range if there is more than 15 sheets, and then paste it to any sheets after sheet #15 all the way until the last active worksheet.
 
Upvote 0
Have you tried ISMII or my suggested codes, let me know if that works for you. Just change the value of 16 to 15 :)
 
Upvote 0
Try this.

Code:
    If Application.Sheets.Count > 16 Then
    Sheets("Sheet1").Select
        Range("A1:L50").Select
    Selection.Copy
    
    Do Until ActiveSheet.Next Is Nothing
        ActiveSheet.Next.Select
        ActiveSheet.Paste
    Loop
    
    End If

Perfect! This code does the trick. thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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