Code to split excel file into multiple sheets based on beginning characters in column

weirdaljr

New Member
Joined
Apr 3, 2011
Messages
2
Hello,

I have used this code below to split a large excel file into multiple sheets from matching column data, but now I need to split it by a partial match (set number of characters from the beginning) from beginning of the column data.

For Example:

select_all_icon.jpg
page_white_copy.png


<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Date Name Description1/1 Jack Safe-221/1 Jan Safe-211/2 Jake Fail-41/2 Jen Fail-31/3 Jen Dont-11/3 Matt Poop-71/4 Mike Fail331/5 Sean Safe-91/6 Pete Pooper1/8 Anne 21-43</code>

So with the code provided below using column 3 I would get 10 different sheets since none of the data in the column is identical. I want to modify the code (or come up with new code) so I can set the number of characters to compare from the beginning of the data in the set column and split into sheets based on that. So if I set it to the first 4 characters in column 3 I would receive only 5 sheets sheets: Safe, Fail, Dont, Poop, & 21-4.

Would anyone kindly assist me with the modifications or new code needed for this? I have searched for a bit with no luck, just keep finding code to check the full cell data for matches in a set column like this code I have:



SPLIT DATA FROM ONE SHEET TO MULTIPLE SHEETS
select_all_icon.jpg
page_white_copy.png


<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Sub parse_data()Dim lr As LongDim ws As WorksheetDim vcol, i As IntegerDim icol As LongDim myarr As VariantDim title As StringDim titlerow As Integervcol = 2 'CHANGE THE COLUMN NUMBER AS PER YOUR NEEDSet ws = Sheets("Data") 'CHANGE THE SHEET NAME AS PER YOUR NEEDlr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Rowtitle = "A1:Z1" 'CHANGE THE TITLE ROW AS PER YOUR NEEDtitlerow = ws.Range(title).Cells(1).Rowicol = ws.Columns.Countws.Cells(1, icol) = "Unique"For i = 2 To lrOn Error Resume NextIf ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Thenws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)End IfNextmyarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))ws.Columns(icol).ClearFor i = 2 To UBound(myarr)ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") ThenSheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""ElseSheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)End Ifws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")Sheets(myarr(i) & "").Columns.AutoFitNextws.AutoFilterMode = Falsews.ActivateEnd Sub</code>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,911
Messages
6,175,327
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