COPY DATA TO MANY WORKSHEETS FROM MASTER SHEET

BABU Baru

New Member
Joined
Nov 5, 2021
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
I need your help to solve my problem. I am learning.

Data in sheet named “Master Sheet” from Column A2:F2 and rows can be many. The header is in Row “A1. The name of students are in Column “A2:A”. I have already created sheets for each students by student name in same workbook.

I want to copy data to appropriate sheet of the student as soon as I enter data and hit “ENTER” key.

A B C D E F

1STUDENT NAMEMATHSENGLISHPHYSICSCHEMISTRYBIOLOGY
2
3
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
VBA Code:
Sub CopyOwnTab()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
On Error GoTo M
Lastrow = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row
Dim ans As String
    For i = 2 To Lastrow
    ans = Sheets("Master").Cells(i, 1).Value
        Sheets("Master").Rows(i).Resize(, 6).Copy Sheets(ans).Rows(Sheets(ans).Cells(Rows.Count, "A").End(xlUp).Row + 1)
        
    Next
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox "No such sheet as  " & ans & " exist"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello Babubaru,

Here's another option which should work well should your data set be extensive:-

VBA Code:
Sub TestBabu()

        Dim wsM As Worksheet, ar As Variant, lr As Long, i As Long
        Set wsM = Sheets("Master")
        lr = wsM.Range("A" & Rows.Count).End(xlUp).Row
        
        wsM.Range("A1:A" & lr).AdvancedFilter 2, , wsM.[Z1], 1
        wsM.Range("Z2", wsM.Range("Z" & wsM.Rows.Count).End(xlUp)).Sort [Z2], 1
        ar = wsM.Range("Z2", wsM.Range("Z" & wsM.Rows.Count).End(xlUp))


Application.ScreenUpdating = False
        
        For i = 1 To UBound(ar)
                Sheets(ar(i, 1)).UsedRange.Clear
                With wsM.[A1].CurrentRegion
                        .AutoFilter 1, ar(i, 1)
                        .Copy Sheets(ar(i, 1)).[A1]
                        .AutoFilter
                End With
        Next i

wsM.Columns("Z").Clear
Application.ScreenUpdating = True

End Sub

The code extracts the unique name values in Column A and temporarily places them into Column Z and are then sorted. These unique values are then placed into an array which is then used to filter on and copy/paste to the relevant work sheets.
Please test the code in a copy of your actual workbook.

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
VBA Code:
Sub CopyOwnTab()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
On Error GoTo M
Lastrow = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row
Dim ans As String
    For i = 2 To Lastrow
    ans = Sheets("Master").Cells(i, 1).Value
        Sheets("Master").Rows(i).Resize(, 6).Copy Sheets(ans).Rows(Sheets(ans).Cells(Rows.Count, "A").End(xlUp).Row + 1)
       
    Next
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox "No such sheet as  " & ans & " exist"
Application.ScreenUpdating = True
End Sub
Sorry, I didn't work.
 
Upvote 0
Hello Babubaru,

Here's another option which should work well should your data set be extensive:-

VBA Code:
Sub TestBabu()

        Dim wsM As Worksheet, ar As Variant, lr As Long, i As Long
        Set wsM = Sheets("Master")
        lr = wsM.Range("A" & Rows.Count).End(xlUp).Row
       
        wsM.Range("A1:A" & lr).AdvancedFilter 2, , wsM.[Z1], 1
        wsM.Range("Z2", wsM.Range("Z" & wsM.Rows.Count).End(xlUp)).Sort [Z2], 1
        ar = wsM.Range("Z2", wsM.Range("Z" & wsM.Rows.Count).End(xlUp))


Application.ScreenUpdating = False
       
        For i = 1 To UBound(ar)
                Sheets(ar(i, 1)).UsedRange.Clear
                With wsM.[A1].CurrentRegion
                        .AutoFilter 1, ar(i, 1)
                        .Copy Sheets(ar(i, 1)).[A1]
                        .AutoFilter
                End With
        Next i

wsM.Columns("Z").Clear
Application.ScreenUpdating = True

End Sub

The code extracts the unique name values in Column A and temporarily places them into Column Z and are then sorted. These unique values are then placed into an array which is then used to filter on and copy/paste to the relevant work sheets.
Please test the code in a copy of your actual workbook.

I hope that this helps.

Cheerio,
vcoolio.
This VBA code is not working
 
Upvote 0
Provide a sample of your workbook. This Forum does not provide a means of posting a workbook. You will need to upload it to a CLOUD website
for download and provide the link in your next post.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,830
Members
449,096
Latest member
Erald

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