VBA request: Collapse rows if column value matches

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a range of data in A4:CE<max 73> (maximum number of rows 70 x 83 columns)

B4:B73 contains a 3-character code and the data is sorted alphabetically by this code. Values in row 3 are column index values to be used later for specific column output

Where 3-char code matches, I need to reduce to a single row.
E.g. B4 = ABC, B5 = ABC, L4 = 10, M4 = 10, N5 = 20, O5 = 20

Into: B4 = ABC, L4 = 10, M4 = 10, N4 = 20, 05 = 20 and clear row 5 entirely.
Max 6 rows with matching codes

If both cells(4, c) and cells(5, c) contain values, they should be summed for any column if c where c > 11

E.g. B4 = ABC, B5 = ABC, L4 = 10, M4 = 10, L5 = 20, M5 = 20
Into: B4 = ABC, L4 = 30, M4 = 30 and clear row 5 entirely.

Can anyone suggest VBA solution? Tried to use Dictionary but couldn't get output columns aligned correctly.

TIA,
Jack
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Found solution. Switched column B with A, then ran:
Code:
Sub Macro2()
'
' Macro2 Macro

Dim x As Long

Output 'Creates data as described initially

Application.ScreenUpdating = False
With wTemp
    x = LastRow(wTemp)
    .Cells(x, 1).Offset(1).Consolidate Sources:="'" & .Name & "'!R3C1:R" & x & "C83", Function:=xlSum, TopRow:=False, LeftColumn:=True, CreateLinks:=False
    .Cells(4, 1).Resize(x - 2).EntireRow.Delete
End With
Application.ScreenUpdating = True
End Sub
Then switch column A back with column B
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,287
Members
449,218
Latest member
Excel Master

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