Copying/Pasting data to tab sharing same name

ManhattanJM

New Member
Joined
Feb 19, 2022
Messages
6
Office Version
  1. 2016
Platform
  1. MacOS
Hi everyone,

Just having a bit of difficulty with the last two steps of a macro I'm trying to piece together. I have the below data and I'm trying to organize the data in four steps.

1. Create new tabs for each name✅

2. Copy and paste the header to each tab✅

3. Copy and paste the rows for each player to their corresponding tab❌

4. Add a footer row in each tab that will take the sum total of the data❌

I've got one and two done based on the below code, but having difficulty getting the player details to the corresponding tab and the sum footer row. For example, I already have a tab named Russell Westbrook, but now I want to take rows 2,3,4,5, and 6 and paste them from Sheet1 to the Russell Westbrook sheet. If anyone could help that would be excellent! Thank you

1645291372040.png



1.)
Sub AddSheets()
Dim xRg As Excel.Range
Dim wSh As Excel.Worksheet
Dim wBk As Excel.Workbook
Set wSh = ActiveSheet
Set wBk = ActiveWorkbook
Application.ScreenUpdating = False
For Each xRg In wSh.Range("A1:A58")
With wBk
.Sheets.Add after:=.Sheets(.Sheets.Count)
On Error Resume Next
ActiveSheet.Name = xRg.Value
If Err.Number = 1004 Then
Debug.Print xRg.Value & " already used as a sheet name"
End If
On Error GoTo 0
End With
Next xRg
Application.ScreenUpdating = True
End Sub

2.)
Sub CopyHeader()
For Each wsSheet In ThisWorkbook.Worksheets
wsSheet.Rows(1).Value = Worksheets("Sheet1").Rows(1).Value
Next wsSheet
End Sub
 

Attachments

  • 1645291272561.png
    1645291272561.png
    67.2 KB · Views: 5

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Re: 4) You might want to have your Totals row at the top (in row 2) with formulas like =SUM(B3:B99999). That way you can add data to the sheet and not have to use Insert to keep the totals correct. Plus, it puts the Totals data in the same cells on every sheet. Makes it easier for formulas / macros to find the totals row.

Re: 3)

VBA Code:
Dim oneCell as Range

With Sheets("masterSheet")
    For Each oneCell in Range(.Cells(2, 1), .Cells(Rows.Count, 1).End(xlup))
        With oneCell
            Sheets(.Value).Cells(Rows.Count, 1).End(xlUp).Offset(1,0).Resize((1, 8).Value = oneCell.Resize(1, 8).Value
        End With
    Next oneCell
End With
 
Upvote 0
Thank you very much for your time!

That's a great idea about the sum rows.

Apologies, it's been a while since I last used VBA. I'm getting a "compile error : syntax error" on the below

1645295276329.png
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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