Help with a Macro

KiloHotel

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

I have a worksheet with alot of data that was given to me with all the information "Glued" together instead of separated into tabs. :eek:

I have basically the macro figured out that everytime it goes down the sheet and its met with the Keyword SOB that it cuts and copies to the next sheet, That's fine but my issue is that it doesnt "Cut" at the bottom, So as a result the next sheet has the correct data at the top but drags across whatever is below it from the original sheet into it and its not ideal.

Another way of explaining this would be :

I have the original data as this:

SOBDATA 1
TEST1TEST1
TEST2TEST3
SOBDATA 2
TEST3TEST3
TEST4TEST4

<tbody>
</tbody>

All glued together and the macro will drag SOB DATA1 to the next sheet and then all data below it and then subsequently the next sheet after drags Data 2 then everything else after... So i just need it to Cut from the top and then the next time it hits SOB.

This is the Macro I am using:


Sub Splitdata()


Dim Ws As Worksheet
Dim Ar As Areas
Dim i As Long

Set Ws = ActiveSheet
Ws.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = "SOB"
With Ws.Range("D1", Ws.Range("D" & 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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I have removed the quote of your first post from the second as it does not add any further information and just makes the post harder to navigate/read.

<del>To your question: I can't really see what is going wrong with your current code. What columns is that sample data from post#1 in? If there is also data in other columns, can you dummy up a another small set of sample data and show us what the results are and what they should be so we can understand.</del>

Edit: Never mind, I can now see the problem. I'll be back shortly.
 
Last edited:
Upvote 0
Try replaceing the first line below with the second.
Rich (BB code):
<del>Ar(i).Resize(Ar(i + 1).Row - 1).EntireRow.Copy ActiveSheet.Range("A1")</del>
Ar(i).Resize(Ar(i + 1).Row - Ar(i).Row).EntireRow.Copy ActiveSheet.Range("A1")
 
Last edited:
Upvote 0
Perfect! I knew it was something very silly! Just i needed a fresh pair of eyes! Thanking you sir!
 
Upvote 0

Forum statistics

Threads
1,214,407
Messages
6,119,332
Members
448,888
Latest member
Arle8907

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