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
 
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.
Set myAreas = sh1.Range("A12:A" & lr).SpecialCells(2).Areas Getting error no cells found
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Where did you find A12 in my suggestion?
Everything works properly here so you have something that we don't know about. Did you change the Sheet name?
Show us your whole macro without using the quote button again.
 
Upvote 0
Where did you find A12 in my suggestion?
Everything works properly here so you have something that we don't know about. Did you change the Sheet name?
Show us your whole macro without using the quote button again.
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("A13: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
 
Upvote 0
What is in Column A? Keyboard entered data?

I hope by now you disabled the quote button.

Just to try something on a copy of your workbook.

Code:
Sub Try_So_Sheet1()
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, 2).End(xlUp).Row
Set myAreas = sh1.Range("B13:B" & 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 - 3).Resize(, 2).Insert Shift:=xlToRight
    Next i
End Sub
 
Upvote 0
Columns A,B,C,D,E, is all keyboard entered data
tried your code in post #14
im still getting error no cells found i'm using the data set i posted in post #9
 
Upvote 0
If you go to Post #9, on the top example, the example that shows the set-up before macro is run, and click on the little sign left of the A above the 1 so you copy the data.
It should show that you copied the data. Now open a new workbook and in Sheet1 select cell A1, right click and select PasteSpecial and now select "Text".
Copy the code from Post #14 and paste it into Module 1.
Go back to Sheet1 and run the macro. Does it work now because that are the steps I've used and everything works as required.
If that does not work, upload your workbook to a free sharing site like dropbox and let us know the password to collect it.
 
Upvote 0
If you go to Post #9, on the top example, the example that shows the set-up before macro is run, and click on the little sign left of the A above the 1 so you copy the data.
It should show that you copied the data. Now open a new workbook and in Sheet1 select cell A1, right click and select PasteSpecial and now select "Text".
Copy the code from Post #14 and paste it into Module 1.
Go back to Sheet1 and run the macro. Does it work now because that are the steps I've used and everything works as required.
If that does not work, upload your workbook to a free sharing site like dropbox and let us know the password to collect it.
hi tried exactly that and got an error no cells found
 
Upvote 0
It might be an Excel version problem. I have never heard of it before that it could be because it works like a charm here on Excel 2013.
All I can think of is to upload it to dropbox for people to look at.
Maybe someone else knows what the problem is.
 
Upvote 0
It might be an Excel version problem. I have never heard of it before that it could be because it works like a charm here on Excel 2013.
All I can think of is to upload it to dropbox for people to look at.
Maybe someone else knows what the problem is.
how about you change your vba to just select those last two merged cells so we can see what its selecting
 
Upvote 0
It might be an Excel version problem. I have never heard of it before that it could be because it works like a charm here on Excel 2013.
All I can think of is to upload it to dropbox for people to look at.
Maybe someone else knows what the problem is.
hi
i changed this code line
VBA Code:
Set sh1 = ThisWorkbook.Sheets("Sheet1")    '<---- Change as required
to this
VBA Code:
Set sh1 = ActiveWorkbook.ActiveSheet

it worked thanks
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,049
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