Separate Rows Based on Content & Place in Different Worksheets

Small Paul

Board Regular
Joined
Jun 28, 2018
Messages
118
Hi

I have a worksheet [report] which has defining content in column A, e.g.

A1 - 5
A2 - 5
A3 - 7
A4 - 8
A5 - 8 etc

I need to have a new worksheet opened for each (5,7,8) and the content placed in row 10 of the tab.

Please, can anyone help?

Regards
Small Paul.
 
Fluff
Please come to rescue again as this is really odd! The whole thing was working perfectly yesterday and this morning. I now get an error on line 6 below (I have separated it below just for ease):

Code:
Set Ws = ActiveSheet   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each cl In Ws.Range("A2", Ws.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(cl.Value) Then


            .Add cl.Value, Split(Split(cl.Value, "(")(1), ")")(0)


            Sheets.Add(, Sheets(Sheets.Count)).Name = .Item(cl.Value)
            Ws.Range("A1:H1").AutoFilter 1, cl.Value
            Ws.AutoFilter.Range.Offset(1).Copy Sheets(.Item(cl.Value)).Range("A6")

What seems to happen is the last worksheet created does not have column A deleted. Apart from that, it seems fine.
Have I corrupted somehow?
Cheers
Small Paul.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Do you have any cells in col A that don't have a value in ()
 
Upvote 0
No, all the cells are empty.
Macro inserts a new column A, copy/paste column I into A. This works on all of the new sheets created, except for the final one which has all the columns shifted 1 to the right i.e. what should be in column A is in column B
 
Upvote 0
Macro inserts a new column A, copy/paste column I into A
There is no code on this thread that does what you describe.
Also if col A is empty, then the code I supplied won't work as it's looking a col A for the values to filter & name the new sheets.
 
Upvote 0
Code:
    ChDir "Z:\"    ChDir "Z:\Orders"
    Workbooks.Open Filename:= _
        "Z:\Orders\De Vere Daily Update Paul Test.xlsm" _
        , UpdateLinks:=0


    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("I:I").Select
    Selection.Cut
    Columns("A:A").Select
    ActiveSheet.Paste
   Dim cl As Range
   Dim Ws As Worksheet
   
   Set Ws = ActiveSheet
   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each cl In Ws.Range("A2", Ws.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(cl.Value) Then
            .Add cl.Value, Split(Split(cl.Value, "(")(1), ")")(0)
            Sheets.Add(, Sheets(Sheets.Count)).Name = .Item(cl.Value)
            Ws.Range("A1:H1").AutoFilter 1, cl.Value
            Ws.AutoFilter.Range.Offset(1).Copy Sheets(.Item(cl.Value)).Range("A6")
            Call Macro18
         End If
      Next cl
   End With
   Ws.AutoFilterMode = False
End Sub
 
Upvote 0
If you are getting an error on this line
Code:
.Add cl.Value, Split(Split(cl.Value, "(")(1), ")")(0)
It's probably that you have a cell in col A that does not include any brackets
 
Upvote 0
That line is looking for the value inside the brackets, to use as the sheet name.
 
Upvote 0
This is SO frustrating!
The coding was working fine - until a colleague starting using it!!
Using the following code:

Code:
    ChDir "Z:\"    ChDir "Z:\Orders"
    Workbooks.Open Filename:= _
        "Z:\Orders\De Vere Daily Update Paul Test.xlsm" _
        , UpdateLinks:=0


    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("I:I").Select
    Selection.Cut
    Columns("A:A").Select
    ActiveSheet.Paste


   Dim cl As Range
   Dim Ws As Worksheet
   
   Set Ws = ActiveSheet
   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each cl In Ws.Range("A2", Ws.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(cl.Value) Then
            .Add cl.Value, Split(Split(cl.Value, "(")(1), ")")(0)
            Sheets.Add(, Sheets(Sheets.Count)).Name = .Item(cl.Value)
            Ws.Range("A1:H1").AutoFilter 1, cl.Value
            Ws.AutoFilter.Range.Offset(1).Copy Sheets(.Item(cl.Value)).Range("A6")
            Call De_Vere_Daily_Update_Macro_2
         End If
      Next cl
   End With
   Ws.AutoFilterMode = False


End Sub

I am now getting "Runtime Error 1004 - Autofilter method of range class failed" at the line:

Code:
        Ws.Range("A1:H1").AutoFilter 1, cl.Value

Can somebody shed some light on this please.
Cheers
Small Paul.
 
Upvote 0
Do you have any data in A1:H1 on the activesheet?
Also is your data in a table?
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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