Divide sheet1 rows into different sheets with criteria from collumn?

paddingtonbear

New Member
Joined
Dec 7, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Is there any way to CTRL+V random data in Sheet "Klistra in här". And have a macro that reads Collumn A1. Each name it finds that are unique, populate the name in Sheet "Assigned to".
In Sheet "Assigned to" i have a Excel formula that creates a new Sheet for each name from collumn A1. And then read all rows from Sheet "Klistra in här" into all new Sheets containing those names from A1.

Summare:
In 2nd picture i have a formula with a green big button that reads each name from A1 to A15. And when pressed it creates a new Sheet with each name. This already works.
But i need to take data rows with each name and copy rows to the new created Sheets.


Would be really helpful if this is possible to do :)
 

Attachments

  • Ctrl_V_Data_To_Read_From_Macro_And_Find_Name_To_next_Sheet.PNG
    Ctrl_V_Data_To_Read_From_Macro_And_Find_Name_To_next_Sheet.PNG
    114.7 KB · Views: 13
  • names from A1 populates in Sheet Assigned to - and pressing button to create Sheets for each n...PNG
    names from A1 populates in Sheet Assigned to - and pressing button to create Sheets for each n...PNG
    56.9 KB · Views: 13

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Do you simply want to create a new sheet for each unique name in column A of sheet "Klistra in här" and copy each person's data in columns B to F to each new sheet? If this is what you want, there is no need for the "Assigned to" sheet unless it serves a different purpose.
 
Upvote 0
Do you simply want to create a new sheet for each unique name in column A of sheet "Klistra in här" and copy each person's data in columns B to F to each new sheet? If this is what you want, there is no need for the "Assigned to" sheet unless it serves a different purpose.
Exactly this mr. mumps 😊!
Hm okay because sometime in the future i might apply alot of different dates aswell. And then i would like a page to exist still like Sheet "Assigned to" where i can exclude names or dates more easily visually.

I already created a macro that applies my preferred print settings and excluded my main source Sheet. So the only thing i cant figure out how to do is the thing you questioned :) would you be able to help me someday when you got time perhaps. I am no programmer just trying to automate stuff. Tried reading other threads but didnt get those codes to work with my needs or at all without debug errors all over the place. Using Excel office 365 license.
 
Upvote 0
I noticed that in your "Klistra in här" sheet the data starts in row 1. In order for the macro below to work properly, you will need to insert a header row so that the data starts in row 2. Before running the macro, please insert the header row and enter the column headers in row 1.
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim LastRow As Long, i As Long, srcWS As Worksheet
    Set srcWS = Sheets("Klistra in här")
    Dim v As Variant
    v = srcWS.Range("A2", srcWS.Range("A" & Rows.Count).End(xlUp))
    With CreateObject("scripting.dictionary")
        For i = LBound(v) To UBound(v)
            If Not .exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                With srcWS
                    .Range("A1").AutoFilter 1, v(i, 1)
                    .AutoFilter.Range.Offset(1).Copy
                    Sheets.Add after:=Sheets(Sheets.Count)
                    With ActiveSheet
                        .Name = v(i, 1)
                        .Cells(.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial
                    End With
                End With
            End If
        Next i
    End With
    srcWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution
I noticed that in your "Klistra in här" sheet the data starts in row 1. In order for the macro below to work properly, you will need to insert a header row so that the data starts in row 2. Before running the macro, please insert the header row and enter the column headers in row 1.
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim LastRow As Long, i As Long, srcWS As Worksheet
    Set srcWS = Sheets("Klistra in här")
    Dim v As Variant
    v = srcWS.Range("A2", srcWS.Range("A" & Rows.Count).End(xlUp))
    With CreateObject("scripting.dictionary")
        For i = LBound(v) To UBound(v)
            If Not .exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                With srcWS
                    .Range("A1").AutoFilter 1, v(i, 1)
                    .AutoFilter.Range.Offset(1).Copy
                    Sheets.Add after:=Sheets(Sheets.Count)
                    With ActiveSheet
                        .Name = v(i, 1)
                        .Cells(.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial
                    End With
                End With
            End If
        Next i
    End With
    srcWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
Thank you so much. I tested this script today in my "setup", and it works just as desired. Only thing is if its possible to copy Headers from sheet "Klistra in här" to all documents also.
Or i might have to look into making a code line inside the Excel workbook that adjusts this from source sheet after Macro has run and places Headers inside A1 row if this is not possible? :)
 
Upvote 0
Replace this line of code:
VBA Code:
.AutoFilter.Range.Offset(1).Copy
with this one:
VBA Code:
.AutoFilter.Range.Copy
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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