Separating Data into Different Sheets

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
950
Office Version
  1. 2019
Platform
  1. Windows
Hello all,

I am using a web query to pull some data with the following structure:

Row132: Header 1

Rows133-200: Data set 1

Row201: Header 2

Rows201-300: Data set 2


I would like to separate the data sets into 2 different sheets.

The problems i am facing:

- Data is dynamic - Header 1 and Header 2 positions can vary

- Number of rows of data sets can vary

The only constant is that I always know the names of Header 1 and Header 2.

Based on this information is there a formula I can use to separate the data to two different sheets?

many thanks
Andy
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
suppose sample data is like this

Sheet1

*AB
1header1header2
2a1
3w25
4f2
5g34
6h5
7*6
8j7
9k8
10**
11**
12**
13**
14**
15**
16header1header2
17w3
18d5
19f7
20r8
21t9
22g54
23y3

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4


try this macro(moodify)

Code:
Sub test()
Worksheets("sheet2").Cells.Clear
Worksheets("sheet3").Cells.Clear
Worksheets("sheet1").Activate


Dim j As Integer, k As Integer, lastrow As Integer
j = Cells.Find(what:="header1", lookat:=xlWhole, after:=Cells(Rows.Count, 1)).Row
'MsgBox j
k = Cells.Find(what:="header1", lookat:=xlWhole, after:=Cells(j, 1)).Row
'MsgBox k
lastrow = Cells(k, 1).End(xlUp).Row


'MsgBox lastrow
Range(Cells(j, 1), Cells(lastrow, 1)).EntireRow.Copy Worksheets("sheet2").Range("A1")
lastrow = Cells(k, 1).End(xlDown).Row
Range(Cells(k, 1), Cells(lastrow, 1)).EntireRow.Copy Worksheets("sheet3").Range("A1")




End SubSub test()
Worksheets("sheet2").Cells.Clear
Worksheets("sheet3").Cells.Clear
Worksheets("sheet1").Activate


Dim j As Integer, k As Integer, lastrow As Integer
j = Cells.Find(what:="header1", lookat:=xlWhole, after:=Cells(Rows.Count, 1)).Row
'MsgBox j
k = Cells.Find(what:="header1", lookat:=xlWhole, after:=Cells(j, 1)).Row
'MsgBox k
lastrow = Cells(k, 1).End(xlUp).Row


'MsgBox lastrow
Range(Cells(j, 1), Cells(lastrow, 1)).EntireRow.Copy Worksheets("sheet2").Range("A1")
lastrow = Cells(k, 1).End(xlDown).Row
Range(Cells(k, 1), Cells(lastrow, 1)).EntireRow.Copy Worksheets("sheet3").Range("A1")




End Sub
 
Upvote 0

Forum statistics

Threads
1,216,590
Messages
6,131,599
Members
449,657
Latest member
Timber5

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