excel vba that moves over merged cells

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
528
Office Version
  1. 365
Platform
  1. Windows
hi all

i have a data set that looks like below

Book1
ABCDEFGHIJ
1Item #Descriptionqtypriceqty price qty price qty price
200000test 110$12.0020$11.0030$10.00
300001test 2
400002test 3
5
600004test 59$13.0025$9.00
700005test 6
800006test 7
9
1000008test 910$14.0020$15.6630$14.0040$13.00
Sheet1



i would like an excel vba that does this below

Book1
MNOPQRSTUVWX
1Item #Descriptionqtypriceqty price qty price qty price
200000test 110$12.0020$11.0030$10.00
300001test 2
400002test 3
5
600004test 510$13.0025$9.00
700005test 6
800006test 7
9
1000008test 910$14.0020$15.6630$14.0040$13.00
Sheet1


as you can see it moved over every group to the right

any suggestions is greatly appreciated
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Boruch so I am going to assume a group is qty and price. So it that is true Item# 00001 test2 20 $11.00 doesn't look like it has been moved over to the right. Was this by design or did you miss that?
 
Upvote 0
Boruch so I am going to assume a group is qty and price. So it that is true Item# 00001 test2 20 $11.00 doesn't look like it has been moved over to the right. Was this by design or did you miss that?
hi

yes, its by design i want to to only move over the last group.
 
Upvote 0
Boruch so I am going to assume a group is qty and price. So it that is true Item# 00001 test2 20 $11.00 doesn't look like it has been moved over to the right. Was this by design or did you miss that?
hi

any suggestions ?
 
Upvote 0
This assumes you have nothing to the right of the data shown in your example
Code:
Sub Try_So()
Dim myAreas As Areas
Dim sh1 As Worksheet
Dim lr As Long, i As Long, lc As Long, fcel As Long, lcel As Long
Set sh1 = ThisWorkbook.Sheets("Sheet1")    '<---- Change as required
lr = sh1.Cells(Rows.Count, 1).End(xlUp).Row
Set myAreas = sh1.Range("A2:A" & lr).SpecialCells(2).Areas
    For i = 1 To myAreas.Count
        fcel = myAreas(i).Cells(1).Row
        lcel = fcel + myAreas(i).Rows.Count - 1
        lc = Rows(fcel & ":" & lcel).Find("*", , , , 2, 2).Column
        myAreas(i).Offset(, lc - 2).Resize(, 2).Insert Shift:=xlToRight
    Next i
End Sub

Please don't quote this post if you reply. Just extra clutter we don't need.
 
Upvote 0
Set myAreas = sh1.Range("C2:C" & lr).SpecialCells(2).Areas

getting error no cells were found
 
Upvote 0
That is not from what I suggested. The code in Post #5 suggests the first Column (Set myAreas = sh1.Range("A2:A" & lr).SpecialCells(2).Areas)
So you changed it but no explanation why it should be changed. Is the example not representative of your actual data?
The code will work only if Cells A5 and A9, as in your example, are actual empty cells.
So if you changed things, we need to know what is changed.
 
Upvote 0
Boruch we want to make these programs dynamic so set up is important. We have to be consistent in how the data is presented. The below program works if the data looks like the worksheet below. Now there may be a few more things we have to tweek but let's see if this works for you.


VBA Code:
Sub Prog09()
Dim row1 As Long
Dim ColCnt As Long

row1 = Cells(Rows.Count, "A").End(xlUp).Row - 2
ColCnt = Cells(2, Columns.Count).End(xlToLeft).Column
Application.ScreenUpdating = False

For i = 2 To row1 Step 4

Range((Cells(i, ColCnt - 1)), Cells(i, ColCnt)).Select

     Selection.Cut Destination:=Range((Cells(i, ColCnt + 1)), Cells(i, ColCnt + 2))

ColCnt = Cells(i + 4, Columns.Count).End(xlToLeft).Column

Next i
Application.ScreenUpdating = True
End Sub

23-12-26 rev b.xlsm
ABCDEFGHIJK
1Item #Descriptionqtypriceqty price qty price qty price qty
200000test 110$ 12.0020$ 11.0030$ 10.00
300001test 2
400002test 3
5
600004test 59$ 13.0025$ 9.00
700005test 6
800006test 7
9
1000000test 110$ 12.0020$ 11.0030$ 10.0015$ 12.00
1100001test 2
1200002test 3
Data
 
Upvote 0
Boruch we want to make these programs dynamic so set up is important. We have to be consistent in how the data is presented. The below program works if the data looks like the worksheet below. Now there may be a few more things we have to tweek but let's see if this works for you.


VBA Code:
Sub Prog09()
Dim row1 As Long
Dim ColCnt As Long

row1 = Cells(Rows.Count, "A").End(xlUp).Row - 2
ColCnt = Cells(2, Columns.Count).End(xlToLeft).Column
Application.ScreenUpdating = False

For i = 2 To row1 Step 4

Range((Cells(i, ColCnt - 1)), Cells(i, ColCnt)).Select

     Selection.Cut Destination:=Range((Cells(i, ColCnt + 1)), Cells(i, ColCnt + 2))

ColCnt = Cells(i + 4, Columns.Count).End(xlToLeft).Column

Next i
Application.ScreenUpdating = True
End Sub

23-12-26 rev b.xlsm
ABCDEFGHIJK
1Item #Descriptionqtypriceqty price qty price qty price qty
200000test 110$ 12.0020$ 11.0030$ 10.00
300001test 2
400002test 3
5
600004test 59$ 13.0025$ 9.00
700005test 6
800006test 7
9
1000000test 110$ 12.0020$ 11.0030$ 10.0015$ 12.00
1100001test 2
1200002test 3
Data
hi i was just uploading test data my actual date looks like this

Book1
ABCDEFGHIJKLM
1
2
3
4
5
6
7
8
9
10
11
12Item #DescriptionOther 1Other 2Other 3Qty Price Qty Price Qty Price Qty Price
1300000test 110$ 12.0020$11.0030$10.00
1400001test 2
1500002test 3
16
1700004test 59$ 13.0025$ 9.00
1800005test 6
1900006test 7
20
2100008test 910$ 14.0020$15.6630$14.00
22
2300011test 105$100.0010$90.00
2400012test 11
2500013test 12
2600014test 13
2700015test 14
2800016test 15
Sheet1


and what i want is

Book1
OPQRSTUVWXYZAA
1
2
3
4
5
6
7
8
9
10
11
12Item #DescriptionOther 1Other 2Other 3Qty Price Qty Price Qty Price Qty Price
1300000test 110$ 12.0020$11.0030$10.00
1400001test 2
1500002test 3
16
1700004test 59$ 13.0025$ 9.00
1800005test 6
1900006test 7
20
2100008test 910$ 14.0020$15.6630$14.00
22
2300011test 105$100.0010$90.00
2400012test 11
2500013test 12
2600014test 13
2700015test 14
2800016test 15
Sheet1


if you can change your code to accommodate this

thanks
 
Upvote 0
All you have to do is change A2 to A13 in the myAreas line from Post #5.

I am done because your last post is just a copy, quote, from the previous post for no reason what-so-ever in my mind. Like I mentioned previously. One way to clutter the world.
 
Upvote 0

Forum statistics

Threads
1,215,483
Messages
6,125,064
Members
449,206
Latest member
Healthydogs

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