Copy data from Master Sheet to corresponding tab (some sheets may be blank)

surkdidat

Well-known Member
Joined
Oct 1, 2011
Messages
582
Office Version
  1. 365
Hi there

I need some code please where it look at what is in column M and whatever is in this column, it copies the whole row (columns A to T) onto the relevant tab. Tabs are called Team1, Team2, Team3 etc to Team10. I tried recording a macro, filtering on column M and copying to the relevant tab, but this fails as when running the report there will be occasions where a certain Team will have no data to copy across.

This will be programmed into a button which will run the report. Before it does this, I need it to clear all the data, but I take it a simple select.Sheet, ClearAllContents A:T should do that part

Many thanks
 
OH I made such a stupid mistake. the following line
Code:
        Set ws = Sheets(Cells(i, 13).Value)
should have said:
Code:
         Set ws = Sheets(StartSheet.Cells(i, 13).Value)


so the code should have said:

Code:
Sub Button1_Click()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets
    If ws.Name <> ActiveSheet.Name Then ws.Range(ws.Rows(2), ws.Rows(1048576)).Clear

Next

i = 2

Set StartSheet = ActiveSheet
Do Until StartSheet.Cells(i, 13) = ""
    
    Set ws = Sheets(StartSheet.Cells(i, 13).Value)
    With ws
        .Activate
        printrow = .Cells(Rows.Count, "A").End(xlUp).Row

        If printrow = 1 Then printrow = 2

        StartSheet.Range(StartSheet.Cells(i, 1), StartSheet.Cells(i, 20)).Copy .Cells(printrow, 1)
    
    End With


    i = i + 1

Loop


End Sub
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Many thanks - that has solved problem one, problem 2 is that the data seems to replace iself, rather than looking for the next blank line in the tabs to copy the data too
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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