Macro needed for extracting to Tab

KiloHotel

New Member
Joined
Feb 4, 2018
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hi all,

I am wondering if there is a way of extracting a range of cells into seperate tabs from the one long sheet.

Let me give you my issue,

I have one sheet with alot of tables and data, Someone glued it all together and i need each table into separate tabs,

At present it is currently like this:

[TABLE="width: 200"]
<tbody>[TR]
[TD]SOB[/TD]
[TD]BBEE[/TD]
[/TR]
[TR]
[TD]TEST 1[/TD]
[TD]TEST1[/TD]
[/TR]
[TR]
[TD]TEST 2[/TD]
[TD]TEST3[/TD]
[/TR]
[TR]
[TD]TEST 3[/TD]
[TD]TEST3[/TD]
[/TR]
[TR]
[TD]SOB[/TD]
[TD]BBEE[/TD]
[/TR]
[TR]
[TD]TEST11[/TD]
[TD]TEST11[/TD]
[/TR]
[TR]
[TD]TEST12[/TD]
[TD]TEST13[/TD]
[/TR]
</tbody>[/TABLE]


So Anywhere Cell A & B say SOB & BBEE it is a new table all the way down until it says it again. The tables vary in length and they are not all the same. but there is 250+ tables all glued like this (idiotic) but i am screaming for help at this stage if anyone can please


Thanks!
 
In a blank cell somewhere enter this
=COUNTIF(D:D,"SOB")

What answer does it give?
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Ok, try this
Code:
Sub chk()
   Dim Ws As Worksheet
   Dim Ar As Areas
   Dim Rng As Range
   
   Set Ws = ActiveSheet
   With Ws.Range("D1", Ws.Range("D" & Rows.Count).End(xlUp))
      .Replace "SOB", "=XXSOB", xlWhole, , False, , False, False
      Set Ar = .SpecialCells(xlConstants).Areas
      .Replace "=XX", "", xlPart, , False, , False, False
      MsgBox Ar.Count
   End With
End Sub
What does the msgbox say?
 
Upvote 0
Ok, try this
Code:
Sub chk()
   Dim Ws As Worksheet
   Dim Ar As Areas
   Dim Rng As Range
   
   Set Ws = ActiveSheet
   With Ws.Range("D1", Ws.Range("D" & Rows.Count).End(xlUp))
      .Replace "SOB", "=XXSOB", xlWhole, , False, , False, False
      Set Ar = .SpecialCells(xlConstants).Areas
      .Replace "=XX", "", xlPart, , False, , False, False
      MsgBox Ar.Count
   End With
End Sub
What does the msgbox say?


It says 891.
 
Upvote 0
Do you have any blank cells in col D?
 
Upvote 0
Ok try this
Code:
Sub Splitdata()

   Dim Ws As Worksheet
   Dim Ar As Areas
   Dim i As Long
   
   Set Ws = ActiveSheet
   Ws.Range("A" & Rows.Count).End(xlUp).Offset(1).Value = "SOB"
   With Ws.Range("A1", Ws.Range("A" & Rows.Count).End(xlUp))
      .Replace "SOB", "=XXSOB", xlWhole, , False, , False, False
      Set Ar = .SpecialCells(xlFormulas, xlErrors).Areas
      .Replace "=XX", "", xlPart, , False, , False, False
      For i = 1 To Ar.Count - 1
         Worksheets.Add , Sheets(Sheets.Count)
         Ar(i).Resize(Ar(i + 1).Row - 1).EntireRow.Copy ActiveSheet.Range("A1")
      Next i
   End With
End Sub
 
Last edited:
Upvote 0
Ok try this
Code:
Sub Splitdata()

   Dim Ws As Worksheet
   Dim Ar As Areas
   Dim i As Long
   
   Set Ws = ActiveSheet
   Ws.Range("A" & Rows.Count).End(xlUp).Offset(1).Value = "SOB"
   With Ws.Range("A1", Ws.Range("A" & Rows.Count).End(xlUp))
      .Replace "SOB", "=XXSOB", xlWhole, , False, , False, False
      Set Ar = .SpecialCells(xlFormulas, xlErrors).Areas
      .Replace "=XX", "", xlPart, , False, , False, False
      For i = 1 To Ar.Count - 1
         Worksheets.Add , Sheets(Sheets.Count)
         Ar(i).Resize(Ar(i + 1).Row - 1).EntireRow.Copy ActiveSheet.Range("A1")
      Next i
   End With
End Sub

Nothing happened with that one, No error message and no other tab opened... I even went through it with F8 to see if it done anything and nothing..
 
Upvote 0
Bolux forgot to change it back to col D after testing.
Code:
   Ws.Range("[COLOR=#ff0000]D[/COLOR]" & Rows.Count).End(xlUp).Offset(1).Value = "SOB"
   With Ws.Range("[COLOR=#ff0000]D1[/COLOR]", Ws.Range("[COLOR=#ff0000]D[/COLOR]" & Rows.Count).End(xlUp))
 
Last edited:
Upvote 0
Bolux forgot to change it back to col D after testing.
Code:
   Ws.Range("[COLOR=#ff0000]D[/COLOR]" & Rows.Count).End(xlUp).Offset(1).Value = "SOB"
   With Ws.Range("[COLOR=#ff0000]D1[/COLOR]", Ws.Range("[COLOR=#ff0000]D[/COLOR]" & Rows.Count).End(xlUp))

OMFG it worked! I cannot thank you enough for your hard work sir! I think you saved me 7 - 8 days of extraction! I can now tackle this tomorrow... 250+ workbooks. :( YOU THE MAN !!!!
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,325
Members
453,032
Latest member
Pauh

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