VBA code to shorten the number of lines according to the condition

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
172
Office Version
  1. 2010
Platform
  1. Windows
Hi everybody. I need to reduce data table B5:D1000 according to the following condition. If the row value of column C > 0 or the row value of column D is not a number, leave it as is and do nothing. The remaining case is reduced to the value of column D . Then output an area as the image describes. Thank you
Link File:
1685867865112.png
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi
See If this suits you
VBA Code:
Sub test()
    Dim a, w
    Dim i&
        a = Range(Cells(5, 2), Cells(5, 4).End(xlDown)).Cells
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If Not .exists(a(i, 1) & a(i, 2) & a(i, 3)) Then
                .Add a(i, 1) & a(i, 2) & a(i, 3), Array(a(i, 1), a(i, 2), a(i, 3), a(i, 3), 1)
                w = .Item(a(i, 1) & a(i, 2) & a(i, 3))
                w(3) = IIf(a(i, 2) = "", w(3) & "x" & w(4), 0)
                If a(i, 2) = "" Then w(3) = 0
                 .Item(a(i, 1) & a(i, 2) & a(i, 3)) = w
            Else
                w = .Item(a(i, 1) & a(i, 2) & a(i, 3))
                w(2) = w(2) + a(i, 3)
                w(4) = w(4) + 1
                w(3) = IIf(a(i, 2) = "", a(i, 3) & "x" & w(4), "")
                .Item(a(i, 1) & a(i, 2) & a(i, 3)) = w
            End If
        Next
        Cells(4, 7).Resize(.Count, 4) = Application.Index(.items, 0, 0)
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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