Macro to group data

natheplas

Board Regular
Joined
Aug 28, 2016
Messages
97
Hello,

I have a list of product codes, descriptions and locations.

I require a macro based on the highlighted list to create 4 columns with headers please.

Product Code, Decription, Loc, Count, then the data, then a space and then the header again, with data etc etc.

The data is grouped by the second number and letter. for example:

QH180300WTHS180A AIR COOLED MIG TORCH 3MTR2B1A
QH400400LX500A WTR COOLED MIG TORCH 4MTR2B1A
ESF5041H/DUTY PROTECTO BLANKET 2 X 2MTR2B1A
RW25-25T/P W/C 200A 3V2B1A
EAD006FINE HIDE YELLOW TIG GLOVES2B1A
QBD5210BEEZG/GUNHCA 10X060 EURO2B1B
QH250401WBLKCONICAL NOZZLE 250A (PK 25)2B1B
EW405CERED TWIST GRIP 400AMP2B1B
ET2001C11 VICE GRIP CLAMP2B1B
EW600TCEYELLOW TWIST GRIP 600AMP2B1B
ELC04305B4.0MM x 305MM GOUG CARBON [x100]2B1B

The above would become:

Product CodeDescriptionLOCCOUNT
QH180300WTHS180A AIR COOLED MIG TORCH 3MTR2B1A
QH400400LX500A WTR COOLED MIG TORCH 4MTR2B1A
ESF5041H/DUTY PROTECTO BLANKET 2 X 2MTR2B1A
RW25-25T/P W/C 200A 3V2B1A
EAD006FINE HIDE YELLOW TIG GLOVES2B1A
Product CodeDescriptionLOCCOUNT
QBD5210BEEZG/GUNHCA 10X060 EURO2B1B
QH250401WBLKCONICAL NOZZLE 250A (PK 25)2B1B
EW405CERED TWIST GRIP 400AMP2B1B
ET2001C11 VICE GRIP CLAMP2B1B
EW600TCEYELLOW TWIST GRIP 600AMP2B1B
ELC04305B4.0MM x 305MM GOUG CARBON [x100]2B1B

Is it possible for a macro to do this based on my highlighted list, as appose to me continuing to copy and based into a worksheet please?

Thank you so much if someone is smart and kind enough to help! :)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
you could try using the subtotal tool in the Data menu.
it produces close to what you want. then copy / paste values and you have a "flat" copy of all the data with no formulae involved.
1619663158574.png
 
Upvote 0
@natheplas I am not sure what you mean by 'highlighted list". That being said, let's see if we can rephrase your desires so members here can assist you better ...

Step 1) You currently have 3 columns of data in your excel sheet
Step 2) You would like to add header titles to each of those 3 columns of data, as well as providing a new, 4th, column header title for the 'Count'
Step 3) You would like to display the data for the 3 column results below that until the value stored in the 3rd column changes
Step 4) You would like to insert a blank row below the 3rd column each time the value stored in the 3rd column changes
Step 5) In addition to this inserted blank row, you would also like to add another header row for the 4 columns below the inserted blank row, similar to Step 2 above
Step 6) You would like to repeat steps 3 - 5 until all Column 3 values have been processed

That sound right? Also, the 4th column you want added ... 'Count' ... are you purposely leaving those cells blank?
 
Upvote 0
@natheplas I am not sure what you mean by 'highlighted list". That being said, let's see if we can rephrase your desires so members here can assist you better ...

Step 1) You currently have 3 columns of data in your excel sheet
Step 2) You would like to add header titles to each of those 3 columns of data, as well as providing a new, 4th, column header title for the 'Count'
Step 3) You would like to display the data for the 3 column results below that until the value stored in the 3rd column changes
Step 4) You would like to insert a blank row below the 3rd column each time the value stored in the 3rd column changes
Step 5) In addition to this inserted blank row, you would also like to add another header row for the 4 columns below the inserted blank row, similar to Step 2 above
Step 6) You would like to repeat steps 3 - 5 until all Column 3 values have been processed

That sound right? Also, the 4th column you want added ... 'Count' ... are you purposely leaving those cells blank?
Hi Johnny, That is well worded. Thank you for your help.
 
Upvote 0
Give this macro a try...
VBA Code:
Sub SeparateByLocationAddHeaders()
  Dim R As Long, LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Application.ScreenUpdating = False
  For R = LastRow To 2 Step -1
    If Cells(R, "C").Value <> Cells(R - 1, 3).Value Then
      Rows(R).Resize(2).Insert
      Cells(R + 1, "A").Resize(, 4) = Array("Product Code", "Description", "LOC", "COUNT")
    End If
  Next
  Rows(1).Insert
  Range("A1:D1") = Array("Product Code", "Description", "LOC", "COUNT")
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,966
Members
452,539
Latest member
delvey

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