Split worksheet into worksheets based on conditions

gvf

New Member
Joined
Apr 6, 2011
Messages
6
Hello all.
This is my first post in this forum and english isn't my main language, so forgive me if i'm not clear enough or something. Also, I'm using excel 2007 on windows XP SP3

So, i searched a lot and couldn't find any precise answers about issues that arise when we are working on very large datasets. My dataset contains 610.000+ observations, and its a pain to do anything - it crashes a lot, it's very slow and such. Is that normal? Can I do anything to improve it or make it less painful?

With that in mind I was thinking about splitting my dataset so , hopefully, it becomes easier to deal with the amount of data. But i don't want to do it manualy, so I tried to creat a macro or vba procedure, but with no sucess... So here I am.

Ok, I have a dataset with 610.000+ cases and 50+ columms. I wanted to split my main worksheet into various smaller worksheets, based on at least one condition - a columm called "state" - , so I'd have a worksheet for each state present on my main worksheet. How can I do that? And with more than one condition, what do i have to add?

I'm not very good with programming, but I'm at a point that I need to learn it, to stay competitive in my career. Does anyone know a good guide/book/internet page that offers something close to a complete course to excel and vba? I've already done almost all of the "VBA for dummies" book and I still have so much to learn...

Thank you in advance.
Gvf.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Sorry, I'm not sure what you mean. Did you use Excel Explosion or my code?
 
Upvote 0
I used your code, even because i can't install anything in this computer.

Sub Lapta()
Dim lastrow As Long, LastCol As Integer, i As Long, iStart As Long, iEnd As Long
Dim ws As Worksheet
Application.ScreenUpdating = False
With ActiveSheet
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
.Range(.Cells(2, 1), Cells(lastrow, LastCol)).Sort Key1:=Range("H2"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
iStart = 2
For i = 2 To lastrow
If .Range("H" & i).Value <> .Range("H" & i + 1).Value Then
iEnd = i
Sheets.Add after:=Sheets(Sheets.Count)
Set ws = ActiveSheet
On Error Resume Next
ws.Name = .Range("H" & iStart).Value
On Error GoTo 0
ws.Range(Cells(1, 1), Cells(1, LastCol)).Value = .Range(.Cells(1, 1), .Cells(1, LastCol)).Value
.Range(.Cells(iStart, 1), .Cells(iEnd, LastCol)).Copy Destination:=ws.Range("A2")
iStart = iEnd + 1
End If
Next i
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

But i mean, in your code, as far as i understood, it creates new worksheets based on the "H" columm. But if the H columm isn't numeric, like in my data? I let it ran for about 20 minutes and the result was a lot of worksheets, each with varying number of cases. Then i recoded my H columm to numeric, and it worked wonders. So i wanted to know if there's a way to make the code work with non-numeric condition data (tweaking it, i suppose). Hope i made myself clear this time...
 
Upvote 0
It works for me with non-numeric data - that's what I originally developed it for (splitting out data by city).
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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