VBA Help find and then incert

justme1122

New Member
Joined
Mar 6, 2011
Messages
47
Hi guys

Trying to work out how to do the following:

I want to find the headers and then move it and everything under it to the right one colum, ie: change this:
Excel Workbook
ABCD
5Stock
6Accessories
7Blank Tapes
8Chips
9Confectionery
10Disk Repair/Cleaning
11Drinks
12Ice Creams
13Member Admin Fees
14Misc Food Items
15Miscellaneous items
16News/Mags/Books
17Popcorn
18Promo Merchandise
19Virgin Accessories
20Vouchers
21Subtotal
22Ex-rental
23Game, Nintendo Wii
24Game, PlayStation 2
25Game, Playstation 3
26Game, X-Box
27Game, X-Box 360
28Movie, Blu-Ray
29Movie, DVD
30TV, DVD
31Subtotal
32Rental
33Accessories, Nintendo Wii
34Game, Nintendo Wii
35Game, PlayStation 2
36Game, Playstation 3
37Game, X-Box
38Game, X-Box 360
39Movie, Blu-Ray
40Movie, DVD
41TV, DVD
42Subtotal
43Sell Through
44Accessories, PC Compatible
45Game, DreamCast
46Game, Nintendo Wii
47Game, PC compatible
48Game, PlayStation 2
49Game, Playstation 3
50Game, X-Box 360
51Movie, Blu-Ray
52Movie, DVD
53Movie, DVD - Vanilla
54TV, Blu-Ray
55TV, DVD
56Subtotal
Sheet


to this
Excel Workbook
ABCD
5Stock
6Accessories
7Blank Tapes
8Chips
9Confectionery
10Disk Repair/Cleaning
11Drinks
12Ice Creams
13Member Admin Fees
14Misc Food Items
15Miscellaneous items
16News/Mags/Books
17Popcorn
18Promo Merchandise
19Virgin Accessories
20Vouchers
21Subtotal
22Ex-rental
23Game, Nintendo Wii
24Game, PlayStation 2
25Game, Playstation 3
26Game, X-Box
27Game, X-Box 360
28Movie, Blu-Ray
29Movie, DVD
30TV, DVD
31Subtotal
32Rental
33Accessories, Nintendo Wii
34Game, Nintendo Wii
35Game, PlayStation 2
36Game, Playstation 3
37Game, X-Box
38Game, X-Box 360
39Movie, Blu-Ray
40Movie, DVD
41TV, DVD
42Subtotal
43Sell Through
44Accessories, PC Compatible
45Game, DreamCast
46Game, Nintendo Wii
47Game, PC compatible
48Game, PlayStation 2
49Game, Playstation 3
50Game, X-Box 360
51Movie, Blu-Ray
52Movie, DVD
53Movie, DVD - Vanilla
54TV, Blu-Ray
55TV, DVD
56Subtotal
Sheet


Please note that this would be put into a loop and ran over a few hundred imported sheets. The Bold headers have constant names but not a constant cell location. The number of sub heading changes with each sheet.

On second thought there may be an easyer way to achive what im trying to do, is there a way to tell excell to:

=vlookup("drinks",between "STOCK" and the next "subtotal",m,0)


Thanks
so much for your time?
 
Last edited:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Shift_Data()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> Found <SPAN style="color:#00007F">As</SPAN> Range, col <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, Lastrow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> Worksheets<br>        col = 1<br>        <SPAN style="color:#00007F">Set</SPAN> Found = ws.Columns(col).Find("SubTotal", , xlValues, xlWhole, xlByRows, xlNext, <SPAN style="color:#00007F">False</SPAN>)<br>        <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Found <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>            Lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row<br>            <SPAN style="color:#00007F">If</SPAN> Found.Row <> Lastrow <SPAN style="color:#00007F">Then</SPAN><br>                <SPAN style="color:#00007F">Do</SPAN><br>                    ws.Range(Found.Offset(1), ws.Cells(Lastrow, col)).Insert Shift:=xlToRight<br>                    col = col + 1<br>                    <SPAN style="color:#00007F">Set</SPAN> Found = ws.Columns(col).Find("SubTotal")<br>                <SPAN style="color:#00007F">Loop</SPAN> <SPAN style="color:#00007F">Until</SPAN> Found.Row = Lastrow<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> ws<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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