Splitting worksheet data into multiple worksheets/workbooks by ROW criteria

VBAbeginner2015

New Member
Joined
Aug 20, 2015
Messages
6
Hi

I'm trying to spilt data in a worksheet into multiple worksheets or multiple workbooks using rows instead of columns. I haven't been able to find any previous threads that do not relate to columns.

Basically I have the following all in one worksheet (called 'Master'):

Blank row
Header
Blank row
Title (which is blue text)
Blank row
Text
text
text
Blank row
Blank row
Title (which is blue text)
Blank row
Text
Blank row

etc...


I'd like to be able to spilt the worksheet by the title (in blue text) so that everything from the blue title to the next blue title is in a new worksheet. Is there any way I can do this please? The text rows can vary in length so there's never a set amount of rows it can be spilt by.

Thanks all
 
VBAbeginner2015,

Thanks again.

Here is a macro solution for you to consider, based on the screenshots that you have provide.

Sample raw data:


Excel 2007
ABCDEFGH
1
2Overall Tables
3
4Plant 1
5
6VehicleInput 1Input 2Input 3Input 4Input 5Input 6
7345
8564
9654
10343
11978
12243
13
14
15Plant 2
16
17VehicleInput 1Input 2
18120
19431
20545
21
22Plant 3
23
24VehicleInput 1Input 2
25330
26
27Plant 4
28
29VehicleInput 1Input 2
30347
31809
32879
33
Master


After the macro in the new worksheets:


Excel 2007
ABCDEFGH
1Plant 1
2
3VehicleInput 1Input 2Input 3Input 4Input 5Input 6
4345
5564
6654
7343
8978
9243
10
Plant 1



Excel 2007
ABCD
1Plant 2
2
3VehicleInput 1Input 2
4120
5431
6545
7
Plant 2



Excel 2007
ABCD
1Plant 3
2
3VehicleInput 1Input 2
4330
5
Plant 3



Excel 2007
ABCD
1Plant 4
2
3VehicleInput 1Input 2
4347
5809
6879
7
Plant 4


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub CreatePlants()
' hiker95, 08/20/2015, ME876991
Dim wm As Worksheet, p As String
Dim Area As Range, sr As Long, er As Long, lc As Long, nr As Long
Application.ScreenUpdating = False
Set wm = Sheets("Master")
With wm
  For Each Area In wm.Range("A3", wm.Range("A" & wm.Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
    With Area
      sr = .Row
      er = sr + .Rows.Count - 1
      If .Rows.Count = 1 Then
        p = wm.Cells(sr, 1).Value
        If Not Evaluate("ISREF('" & Trim(p) & "'!A1)") Then Worksheets.Add(After:=Sheets(Sheets.Count)).Name = Trim(p)
        Sheets(p).Cells(1, 1) = p
        nr = 3
      Else
        lc = wm.Cells(sr, Columns.Count).End(xlToLeft).Column
        wm.Range(wm.Cells(sr, 1), wm.Cells(er, lc)).Copy Sheets(p).Range("A" & nr)
        Sheets(p).Columns(1).Resize(, lc).AutoFit
        Application.CutCopyMode = False
      End If
    End With
    wm.Activate
  Next Area
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the CreatePlants macro.
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
VBAbeginner2015,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,216,106
Messages
6,128,863
Members
449,473
Latest member
soumyahalder4

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