Sorting table to new sheets in the same worksheet..

erdow

New Member
Joined
May 30, 2021
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hi to all,

I have a report about 5.000 rows long and it starst from 3. row (there is a headline at 2. row)
There are another vba code to get region names to column A and after that i need another vba code to copy every region data to another sheet on the same workbook.
My exact data is very long, its form A to KP and 5.000 rows.
What i need is , When i run the vba code, first it must sort them(i meant a:kp) by column A (i meant by region) then copy them according to their region name to new sheets (sheet name must be same as region name) (and main page must stay unchanged with all data sorted by region names) (every sheet must have header i meant headline, which is 2. row for hole report)
Is it possible?
Thanks.
 

Attachments

  • sort vba.jpg
    sort vba.jpg
    219.9 KB · Views: 15

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try:
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim i As Long, v As Variant, ws As Worksheet
    Set ws = ActiveSheet
    v = ws.Range("A3", ws.Range("A" & ws.Rows.Count).End(xlUp)).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                With ws.Range("A2")
                    .CurrentRegion.AutoFilter 1, v(i, 1)
                    ws.AutoFilter.Range.Copy
                    If Not Evaluate("isref('" & v(i, 1) & "'!A1)") Then
                       Sheets.Add(After:=Sheets(Sheets.Count)).Name = v(i, 1)
                       ActiveSheet.Range("A1").PasteSpecial
                    End If
                End With
            End If
        Next i
    End With
    ws.Range("A2").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim i As Long, v As Variant, ws As Worksheet
    Set ws = ActiveSheet
    v = ws.Range("A3", ws.Range("A" & ws.Rows.Count).End(xlUp)).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                With ws.Range("A2")
                    .CurrentRegion.AutoFilter 1, v(i, 1)
                    ws.AutoFilter.Range.Copy
                    If Not Evaluate("isref('" & v(i, 1) & "'!A1)") Then
                       Sheets.Add(After:=Sheets(Sheets.Count)).Name = v(i, 1)
                       ActiveSheet.Range("A1").PasteSpecial
                    End If
                End With
            End If
        Next i
    End With
    ws.Range("A2").AutoFilter
    Application.ScreenUpdating = True
End Sub
Thank you so much for your fast solution mumps.
It works great.
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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