Creating different sheets from data in the first sheet,

Jo4x4

Board Regular
Joined
Jan 8, 2011
Messages
136
Hi everybody! I have a very simple spreadsheet with all the data in sheet 1. I would like to split that data into different sheets. I tried vlookup, and can find the first match, but no second or third match.
Potholes
2/5/2017

<colgroup><col width="101" style="width:76pt"> </colgroup><tbody>
</tbody>
John
Streetlights8/6/ 2017Peter
Water leaks3/4/2017Dave
Potholes1/6/2017Adam
Potholes3/2/2017Pete

<tbody>
</tbody>

I then want sheets named "Potholes", "Streetlights", "Water Leaks" with the Pothole sheet containing the 3 instances and names.


Thanks a stack in advance!

Jo

Windows 7, Excel 2007
 
OK, thanks for the file, a few things that you need to do as follows
1) delete all the extra sheet so that only the 2017 sheet remains.
2) in the VBE select insert > Module then remove the code from the sheet module & paste it into the new module 1
3) right click the button2 > Assign macro & select ShtFltrCopy (this needs to be done as the macro has been moved in part 2) )
4) Select the developer tab > Macro security > Trusted Locations > If the location of the file is not in the list add it.
5) Save & close, then reopen it & click Button 2
Hopefully this will solve the problems.
 
Last edited:
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Thanks a stack Fluff!!! Working like a charm. Any way to keep my main sheet to the far left?

Thanks again
Jo
 
Upvote 0
Oops, just ran into a snag. It created all the sheets, but as soon as I add any info it gives the 400 error again. I am going to be adding people all the time, and occasionally another type of Column A.
 
Upvote 0
OK delete the code you have & replace with this
Code:
Option Explicit

Sub ShtFltrCopy()

    Dim Dict As Object
    Dim Ky As Variant
    Dim Cl As Range
    Dim UsdRws As Long
    Dim Ws As Worksheet

Application.ScreenUpdating = False
    Set Dict = CreateObject("scripting.dictionary")

    With Sheets("2017")
        UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
    
        For Each Cl In .Range("A2:A" & UsdRws)
            If Not Dict.exists(Cl.Value) Then Dict.Add Cl.Value, Nothing
        Next Cl
    
        For Each Ky In Dict.keys
            If ShtExists(Left(Ky, 31)) Then
                Set Ws = Sheets(Left(Ky, 31))
                Ws.Cells.Clear
                .Range("A1").AutoFilter Field:=1, Criteria1:=Ky
                .Range("A1:C" & UsdRws).SpecialCells(xlVisible).Copy Ws.Range("A1")
            Else
                Set Ws = Worksheets.Add(after:=Sheets(1))
                Ws.Name = Left(Ky, 31)
                .Range("A1").AutoFilter Field:=1, Criteria1:=Ky
                .Range("A1:C" & UsdRws).SpecialCells(xlVisible).Copy Ws.Range("A1")
            End If
        Next Ky
        .AutoFilterMode = False
    End With
    Sheets("2017").Activate

End Sub

Function ShtExists(ShtNme As String, Optional Wbk As Workbook) As Boolean

    If Wbk Is Nothing Then Set Wbk = ThisWorkbook
    On Error Resume Next
    ShtExists = (LCase(Wbk.Sheets(ShtNme).Name) = LCase(ShtNme))
    On Error GoTo 0

End Function
If a sheet already exists, this will clear the sheet & then add the info, if a sheet doesn't exist, then it will be added.
 
Upvote 0
I don't know how to thank you for your help. Clearly, this is way beyond my scope of knowledge. When I added a name to an existing column A "problem", it ran the debugger and highlighted The following after the Else command: WS.Name=Left(KY,31). It also created a new sheet with a number.
 
Upvote 0
It also creates Filter buttons next to the header row headings...

It was just a name with "water" in Column A.
 
Last edited:
Upvote 0
Ok, found the problem: One of the names did not have a "problem" Column A. As soon as I rectified that, it is working great! Thanks again!!!!
 
Upvote 0

Forum statistics

Threads
1,215,358
Messages
6,124,487
Members
449,165
Latest member
ChipDude83

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