Consulting

Results 1 to 2 of 2

Thread: Solved: How to combine the rows?

  1. #1
    VBAX Contributor
    Joined
    Nov 2009
    Posts
    114
    Location

    Solved: How to combine the rows?

    How to combine the row

    From

    Name Product Price
    A 123 40
    A 123 40
    A 456 15
    A 456 15
    A 456 15

    To

    Name Product Price
    A 123 80
    A 456 30

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]


    Public Sub ProcessData()
    Dim Lastrow As Long
    Dim i As Long
    Dim cell As Range

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = Lastrow - 1 To 2 Step -1

    If .Cells(i, "B").Value = .Cells(i + 1, "B").Value Then

    .Cells(i, "C").Value = .Cells(i, "C").Value + .Cells(i + 1, "C").Value
    .Rows(i + 1).Delete
    End If
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •