+ Reply to Thread
Results 1 to 3 of 3

counting and comparing...

  1. #1
    Registered User
    Join Date
    09-07-2006
    Posts
    1

    Smile counting and comparing...

    I have three columns of data, the first has names, the second has country and the third is populated by age. The list is not a defined length (may be 100 or 'n' rows long) and may contain duplicates (the same named person more than once).

    What I would like to do is have an algorithm that does two things, the first is to go through the list and add up the ages of everyone who has the same name and then replace the rows that share the same name with the single entry that shows the agregate age.

    Finally I would like it to do the same thing but by breaking it down by country...

    I think this is a fairly simple thing to do in VBA, I know how to do it in excel but would be great if someone could offer guidance on how to do it in VBA?

    Thanks!

  2. #2
    Registered User
    Join Date
    08-09-2006
    Posts
    30
    I see one problem, are all people with the same name from the same country? You would like to consolidate all the same names, but what if they are from different countries?

  3. #3
    Registered User
    Join Date
    08-09-2006
    Posts
    30
    This is close I think, it doesnt like the Range statements in the middle of the for loop, although my VB knowledge isnt large enough to say why. If someone could just correct that syntax this could should work.

    Sub macro()
    lastcell = lastRowpub(1, Sheet1)


    For i = 1 To lastcell

    For J = i + 1 To lastcell
    Range("A" & i).Select
    If Selection = Range("a" & J) & Range("B" & i) = Range("B" & J) Then
    Selection = Range("C" & i) = Range("C" & J)

    Rows(J).Delete
    J = i + 1
    End If
    Next J

    Next i


    End Sub

    Function lastRowpub(colnum As Long, Optional Sh As Worksheet) As Long
    ' Count Rows in table
    If Sh Is Nothing Then Set Sh = ActiveSheet
    lastRowpub = Sh.Cells(Sh.Rows.Count, colnum).End(xlUp).Row
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1