Consulting

Results 1 to 7 of 7

Thread: Solved: Macro for countif

  1. #1

    Solved: Macro for countif

    i have a list of items in a column. some items may be the same and gets repeated in the came column.
    I want to extract every item name in another spreadsheet column only once so that those duplicates will not be repeated again.

    Is it possible?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by sebas1102
    i have a list of items in a column. some items may be the same and gets repeated in the came column.
    I want to extract every item name in another spreadsheet column only once so that those duplicates will not be repeated again.

    Is it possible?
    Look at Data>Filter>ADvanced Filter, it has an option for Unique Entries.

  3. #3
    yup but i need it in macro to add to another sheet so that there will be no duplicates... i need to collate data. i need to do a countif in a new sheet and if counif>0 in the 2nd sheet means the item has already been added so it can proceed on to the next row.
    Can u help me? i am very lost...

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    You can still use Advaned filter - trick is to start from the target sheet - record yourself setting it up to get code - it's pretty straightforward.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    =( still cannot be done bcos it is different workbook....*pluck hair*

  6. #6
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by sebas1102
    yup but i need it in macro to add to another sheet so that there will be no duplicates... i need to collate data. i need to do a countif in a new sheet and if counif>0 in the 2nd sheet means the item has already been added so it can proceed on to the next row.
    Can u help me? i am very lost...
    Not sure of the details of what you want to do here, but you can use collections to extract unique items e.g.
    [vba]Option Explicit
    '
    Sub GetUniqueItems()
    '
    Dim UniqueItem As Collection, Cell As Range, N As Long
    '
    Set UniqueItem = New Collection
    '
    Application.ScreenUpdating = False
    '
    On Error Resume Next
    'get all the unique items in column A
    For Each Cell In Range("A1", Range("A" & Rows.Count).End(xlUp))
    'can't have duplicates in a collection
    UniqueItem.Add CStr(Cell), CStr(Cell)
    Next
    '
    'put the unique items in column B
    For N = 1 To UniqueItem.Count
    Range("B" & N) = UniqueItem(N)
    Next
    Application.ScreenUpdating = True
    '
    End Sub[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Quote Originally Posted by sebas1102
    =( still cannot be done bcos it is different workbook....*pluck hair*
    You seem to be looking for excuses. You didn't say it was a different workbook but, anyway, it *can* still be done. Have you tried it?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

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