Add to an existing VBA code

BORUCH

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

i have this vba below
VBA Code:
Sub MOVEOVERMERGEDCELLS()
Application.DisplayAlerts = False
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 = ActiveWorkbook.ActiveSheet
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set myAreas = sh1.Range("b12: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
    Application.DisplayAlerts = True
End Sub

which basically does from this below
Daily Promotions V50 12-29-23 MID.xlsx
ABCDEFGHIJKLM
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


to this
Daily Promotions V50 12-29-23 MID.xlsx
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
Sheet2


in sheet 2 i have the exact same format what i want is for the vba to find the last group of "qty" "price" in sheet 2 and add it in that space in sheet 1 where the last group was moved over
see example below


Daily Promotions V50 12-29-23 MID.xlsx
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.00from sheet 2from sheet 230$ 10.00
1400001test 2
1500002test 3
16
1700004test 59$ 13.00from sheet 2from sheet 225$ 9.00
1800005test 6
1900006test 7
20
2100008test 910$ 14.0020$ 15.66from sheet 2from sheet 230$ 14.00
22
2300011test 105$ 100.00from sheet 2from sheet 210$ 90.00
2400012test 11
2500013test 12
2600014test 13
2700015test 14
2800016test 15
Sheet2


any help is greatly appreciated
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
HI

Can someone on this forum please suggest anything

thanks
 
Upvote 0
hi all

i have this vba below
VBA Code:
Sub MOVEOVERMERGEDCELLS()
Application.DisplayAlerts = False
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 = ActiveWorkbook.ActiveSheet
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set myAreas = sh1.Range("b12: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
    Application.DisplayAlerts = True
End Sub

which basically does from this below
Daily Promotions V50 12-29-23 MID.xlsx
ABCDEFGHIJKLM
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


to this
Daily Promotions V50 12-29-23 MID.xlsx
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
Sheet2


in sheet 2 i have the exact same format what i want is for the vba to find the last group of "qty" "price" in sheet 2 and add it in that space in sheet 1 where the last group was moved over
see example below


Daily Promotions V50 12-29-23 MID.xlsx
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.00from sheet 2from sheet 230$ 10.00
1400001test 2
1500002test 3
16
1700004test 59$ 13.00from sheet 2from sheet 225$ 9.00
1800005test 6
1900006test 7
20
2100008test 910$ 14.0020$ 15.66from sheet 2from sheet 230$ 14.00
22
2300011test 105$ 100.00from sheet 2from sheet 210$ 90.00
2400012test 11
2500013test 12
2600014test 13
2700015test 14
2800016test 15
Sheet2


any help is greatly appreciated

I'm still looking for help on this one

thanks
 
Upvote 0

Forum statistics

Threads
1,215,134
Messages
6,123,237
Members
449,093
Latest member
Vincent Khandagale

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