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:

SOBBBEE
TEST 1TEST1
TEST 2TEST3
TEST 3TEST3
SOBBBEE
TEST11TEST11
TEST12TEST13

<tbody>
</tbody>


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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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