How to change to increment by one instead of adding the sum

TylerCross

New Member
Joined
Jan 5, 2021
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
Hello Everyone.
I am current using a code that consolidates rows. In my code I have the option in one of the columns to add the sum of the rows. I am wanting to change the code to just code the number of row instead of adding the sum of the numbers. I am having a trouble time trying to figure out a way to do this. The part of the code that is highlighted red is where the sum is occurring.
Any help is greatly appreciated.
Have a great day!

Rich (BB code):
Sub mergeCategoryValues2()
    Dim lngRow As Long
    With Sheet2
        Dim columnToMatch As Integer: columnToMatch = 1
        Dim columnToConcatenate As Variant: columnToConcatenate = 22
        Dim columnToSum As Integer: columnToSum = 2

        lngRow = .Cells(65536, columnToMatch).End(xlUp).Row
        .Cells(columnToMatch).CurrentRegion.Sort key1:=.Cells(columnToMatch), Header:=xlYes

        Do
            If .Cells(lngRow, columnToMatch) = .Cells(lngRow - 1, columnToMatch) Then
                .Cells(lngRow - 1, columnToConcatenate) = .Cells(lngRow - 1, columnToConcatenate) & "; " & .Cells(lngRow, columnToConcatenate)
                .Cells(lngRow - 1, columnToSum) = .Cells(lngRow - 1, columnToSum) + .Cells(lngRow, columnToSum)
                .Rows(lngRow).Delete
            End If

            lngRow = lngRow - 1
        Loop Until lngRow = 1
    End With
    MsgBox (" Macro Complete!  ")

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Are you trying to get a count of how many rows match each value in col A?
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,451
Members
449,161
Latest member
NHOJ

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