Excel VBA - need to rollup sub products onto a single product line for editing

Autumnscribe

New Member
Joined
Jul 10, 2021
Messages
8
Office Version
  1. 2016
Hi All
Disclosure: I've cross posted this here but no solution yet.

VBA novice. Need to roll-up product lines to the SKU level. E.g. I've got:
Item_IDDistribution TypeSKU number
HELPER ROW
5327978DC673386
5327978DSD673386

And I want:
Item_IDDistribution TypeSKU number
5327978DC DSD673386

I haven't been able to get a concat formula or the & built in concat working.

VBA Code:
Sub ConCatToSKU()

'Note for testing - delete any rows past 20

Dim LastRow As Integer

Dim CurrentRow As Integer

LastRow = ActiveSheet.UsedRange.row - 1 + ActiveSheet.UsedRange.Rows.Count

CurrentRow = 2



Range("A:A").NumberFormat = "General"

      Do While CurrentRow <= LastRow

      ' Writes a flag in an unused cell I can use as an IF criteria

             If IsEmpty(Range("E" & CurrentRow).Value) = True Then

             Range("DA" & CurrentRow).Value = "ZZZZ"

                      If Range("DA" & CurrentRow).Value = "ZZZZ" Then

                            'I was just testing writing a formula into the helper row

                             Range("E" & CurrentRow).Formula = "=Concat(E3,E5)"

                             'I NEED TO HAVE THIS CONCAT FORMULA RUN FOR ALL THE UNIQUE VALUES IN COL E

                       End If

                 End If



CurrentRow = CurrentRow + 1

Loop

End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
@Autumnscribe I don't fully appreciate your intentions nor the data layout. However, assuming that you are happy to have hard values rather than formula ? and that Column E is Distribution Type? Then maybe code more like the below?

VBA Code:
Sub ConCatToSKU()

'Note for testing - delete any rows past 20

Dim LastRow As Integer
Dim CurrentRow As Integer
Dim Helper as Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

LastRow = Range("E" & Rows.Count).End(xlUp).row. ' Avoid using used range

CurrentRow = 2

Range("A:A").NumberFormat = "General"  '?????????

      Do While CurrentRow <= LastRow

             If IsEmpty(Range("E" & CurrentRow).Value) = True Then
                Helper = CurrentRow
                Range("D" & Helper).Value = Range("D" & Helper + 1).Value
                Range("F" & Helper).Value = Range("F" & Helper + 1).Value
             End If

                Range("E" & Helper).Value = Trim(Range("E" & Helper).Value) & " " & Range("E" & CurrentRow + 1).Value

        CurrentRow = CurrentRow + 1

Loop
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

MRXLMAY21.xlsm
DEF
1IDTypeSKU
2
35327978DC673386
45327978DSD673386
55327978ABC673386
65327978XYZ673386
7
85327999TST673399
95327999TST2673399
Sheet3


MRXLMAY21.xlsm
DEF
1IDTypeSKU
25327978DC DSD ABC XYZ 673386
35327978DC673386
45327978DSD673386
55327978ABC673386
65327978XYZ673386
75327999TST TST2 673399
85327999TST673399
95327999TST2673399
Sheet3

Hope that helps.
 
Upvote 0
Thanks SN much appreciated.
I got pulled on to another job this week. I ll go through your code on weekend and come back with questions.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

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