Group into sheets

gdspeare

Board Regular
Joined
Oct 8, 2002
Messages
198
I have data in a worksheet sorted by column H. I would like to have all similar rows pasted in a new sheet named with the appropriate group name


Help,

thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
re

Hi gdspeare if i understand what you want, I have created a sheet for my local swimming club. i enter their names and results in and i then run the following code, it will copy the date to a new sheet and name the sheet to what the name in column "a" is. it will group the last names together on the one sheet. I have also added something like everytime i run the code it will delete all the data except for the "0summary-sheet"
just change the sheet names and ranges to suit your needs.

Sub CreateSheets()

With Worksheets("0summary")
For I = .Range("a65536").End(xlUp).Row To 2 Step -1

If Not SheetExists(.Cells(I, 1).Value) Then

'COPY SHEET
Worksheets.Add After:=Worksheets(Sheets.Count)
ActiveSheet.Name = .Cells(I, 1).Value

'COPY HEADER
.Range("A1:Z1").Copy
ActiveSheet.Paste Destination:=ActiveSheet.Range("A1")

End If

Next I
.Activate
.Range("a1").Select
Application.CutCopyMode = False
End With
End Sub

Private Function SheetExists(sname) As Boolean
' Returns TRUE if sheet exists in the active workbook
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then SheetExists = True _
Else: SheetExists = False
End Function



Sub deletesheet()
Dim I As Integer
Dim vrtsheet As Variant
Dim question As Boolean
For Each vrtsheet In Worksheets
question = False
For I = Range("a65536").End(xlUp).Row To 2 Step -1
If vrtsheet.Name = Worksheets("0summary").Cells(I, 1).Value Or vrtsheet.Name = "0summary" Then
question = True
End If

Next I
If question = False Then
Application.DisplayAlerts = False
vrtsheet.Delete
Application.DisplayAlerts = True
End If

Next vrtsheet

Worksheets("0summary").Activate
Worksheets("0summary").Range("a1").Select
End Sub

Sub copydata()

Dim I As Integer
Dim vrtsheet As Variant

For Each vrtsheet In Worksheets
If vrtsheet.Name <> "0summary" Then
vrtsheet.Range("a2:z10").ClearContents

End If

Next vrtsheet

For I = Range("A65536").End(xlUp).Row To 2 Step -1
If Cells(I, 1).Value <> " " Then
Rows(I).Copy Destination:=Sheets(Cells(I, 1).Value).Range("a65536").End(xlUp).Offset(1, 0)



End If

Next I
Worksheets("0summary").Activate
Worksheets("0summary").Range("a1").Select
End Sub



Sub SortSheets()
Dim I As Integer, J As Integer
For I = 1 To Sheets.Count
For J = 1 To I - 1
If UCase(Sheets(I).Name) < UCase(Sheets(J).Name) Then
Sheets(I).Move before:=Sheets(J)
Exit For
End If
Next J
Next I
Worksheets("0summary").Activate
Worksheets("0summary").Range("a1").Select
End Sub


I then run the code of a button like this


Sub Macro4()
'
' Macro4 Macro
'
'

'
Application.Run "'swim test.xls'!ThisWorkbook.CreateSheets"
Application.Run "'swim test.xls'!ThisWorkbook.copydata"
Application.Run "'swim test.xls'!ThisWorkbook.deletesheet"
Application.Run "'swim test.xls'!ThisWorkbook.SortSheets"
End Sub



cheers
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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