Macro to split up data from one column into multi sheets

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I'm looking for a macro to split the data up into different sheets,
The problem I have is there is no set number of rows between data so we have to find a word and use this word as the break for each new sheet, so I'm hoping someone can help me deal with this.

Heres what I have,

The document currently only has one tab, I will be running this on several docs but whilst I don't know the name of the sheet it will always be Sheets(1)
this sheet has data in column A and this is what I want to split up.

The criteria for splitting the rows is each section begins with a cell that starts with the words "Structure =" (
and some other word)
so I want to split the data up using "Structure =" as the first row and the next "Structure =" as the last row -1

so we look down find
"Structure =" copy that section into its own tab and if possible rename the tab the word that comes after
"Structure ="

heres an example of what I have:

ABC
1these first few line will not contain any importatant data.
2
3there can be empty rows in the sheet
4
5data
6data
7
Structure = Tony​
<strike></strike>
so first we start here
8
and create a new tab called "Tony"
9blarcopy and paste all this data
10


11bblarr

12blar

13
down to here!
14
Structure = Bill​
<strike></strike>
then we create another tab called "Bill"
15blarcopy and paste all this
16blar

17


18more blar

19blardown to here!
20
Structure = Dave​
<strike></strike>
then tab "Dave"
21blar

22


23blarcopy all in dave section
24
Structure = bob
<strike></strike>
and finally BOB,
25last one wont have a structure
26not sur how you deal with this but to end of data.
27
28
29

<tbody>
</tbody>
So that's what I need, if you can help me please do.

Thank you very much

Tony
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try
Code:
Sub tonywatsonhelp()
   Dim Ar As Areas
   Dim i As Long, Lr As Long
   Dim Nme As String
   
   With Sheets(1)
      Lr = .Range("A" & Rows.Count).End(xlUp).Row
      With .Range("A1:A" & Lr)
         .Replace "Structure", "=XXXStructure", , , False, , False, False
         Set Ar = .SpecialCells(xlFormulas, xlErrors).Areas
         .Replace "=XXXStructure", "Structure", , , False, , False, False
      End With
      For i = 1 To Ar.Count
         Nme = Trim(Split(Ar(i).Item(1), "=")(1))
         Sheets.Add(, Sheets(Sheets.Count)).Name = Nme
         If i < Ar.Count Then
            Range(Ar(i), Ar(i + 1).Offset(-1)).Copy Sheets(Nme).Range("A1")
         Else
            Range(Ar(i), .Range("A" & Lr)).Copy Sheets(Nme).Range("A1")
         End If
      Next i
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,105
Members
449,066
Latest member
Andyg666

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