VBA for moving sections

Leo55

New Member
Joined
Aug 10, 2022
Messages
18
Office Version
  1. 2010
Platform
  1. Windows
Hello,

Don't know if this is possible, I have done some playing around and it has beaten me.

I get a spreadsheet which has 2 different datasets on it, one below the other, the length of the data sets vary. So I am having trouble as the row the second data set start on changes.

What I am trying to do is write a macro to search for the header "Count" and then select the A to M (13) on the row and then all data below that to move to a second tab.

Is this possible, am I just being inexperienced here?

Thank you in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
So here is an a cut down sort of view, ( Below), so the first data set is rows 1 -11, again this varies significantly, and this is a cut down sanitized version, the second data set start on here at row 12 with new headers (the first one starting as Count), the second data base, is alway 13 columns (A-M) but varies in length. What I would like to do is move the headers on for the second database (Row 12 in this example) and move that row and all below it (can be the entire rest of the worksheet) to a second sheet.

Hope this assists.

Thanks again.

Book1
ABCDEFGHIJKLM
1CustomerTypeNumberDate TimeAddressOperatorDistrictInvoiceProviderLatitudeLongitudeDealing Staff
2Mr Smith212345601/01/20201200123 High StreetEEYorkshireSentEE123467894580484Bill
3Mr Smith212345602/01/20201201124 High StreetEEYorkshireSentEE123467894580484Bill
4Mr Smith212345603/01/20201202125 High StreetEEYorkshireSentEE123467894580484Bill
5Mr Smith212345604/01/20201203126 High StreetEEYorkshireSentEE123467894580484Bill
6Mr Smith212345605/01/20201204127 High StreetEEYorkshireSentEE123467894580484Bill
7Mr Smith212345606/01/20201205128 High StreetEEYorkshireSentEE123467894580484Bill
8Mr Smith212345607/01/20201206129 High StreetEEYorkshireSentEE123467894580484Bill
9Mr Smith212345608/01/20201207130 High StreetEEYorkshireSentEE123467894580484Bill
10Mr Smith212345609/01/20201208131 High StreetEEYorkshireSentEE123467894580484Bill
11Mr Smith212345610/01/20201209132 High StreetEEYorkshireSentEE123467894580484Bill
12CountSite NameaddressOperatorLogisticsSentWeightFirst NameSurnameAddressEmployee NumberVehicleChecked
13455HQ45 All saint streetO2YesNo155gJohnSmith123 High Street45789VH48AWQY
1487Base46 All saint streetEEYesNo155gJohnSmith124 High Street45789VH48AWQY
15159WFH47 All saint streetVodaphoneYesNo155gJohnSmith125 High Street45789VH48AWQN
16485HQ48 All saint streetO3YesNo155gJohnSmith126 High Street45789VH48AWQN
1722Base49 All saint streetEEYesNo155gJohnSmith127 High Street45789VH48AWQN
1848WFH50 All saint streetVodaphoneYesNo155gJohnSmith128 High Street45789VH48AWQY
19268HQ51 All saint streetO4YesNo155gJohnSmith129 High Street45789VH48AWQY
20555Base52 All saint streetEEYesNo155gJohnSmith130 High Street45789VH48AWQY
2148WFH53 All saint streetVodaphoneYesNo155gJohnSmith131 High Street45789VH48AWQY
Sheet1
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
Apologies meant to reply straight to you. Please see above in response. Thanks!!
 
Upvote 0
Try:
VBA Code:
Sub MoveRange()
    Application.ScreenUpdating = False
    Dim count As Range
    Set count = Range("A:A").Find("Count", LookIn:=xlValues, lookat:=xlWhole)
    Range("A" & count.Row, Range("M" & Rows.count).End(xlUp)).Cut Sheets("Sheet2").Range("A1")
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub MoveRange()
    Application.ScreenUpdating = False
    Dim count As Range
    Set count = Range("A:A").Find("Count", LookIn:=xlValues, lookat:=xlWhole)
    Range("A" & count.Row, Range("M" & Rows.count).End(xlUp)).Cut Sheets("Sheet2").Range("A1")
    Application.ScreenUpdating = True
End Sub
That has worked like a dream. Thank you for that!!
 
Upvote 0
You are very welcome.

You are very welcome. :)
Quick question, if I wanted to extend this code to capture another 2-3 columns what would I need to change I have tried to just change "M" to O for example and it seems to then inverse the results and send the first half of my data to the first sheet
 
Upvote 0
Changing "M" to O will work if column O contains data in all the rows until the last used row. Is that the case?
 
Upvote 0
Changing "M" to O will work if column O contains data in all the rows until the last used row. Is that the case?
Thank you, that was the case, I was having a bit of a moment, all fixed and working now.

Thank you!!
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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