+ Reply to Thread
Results 1 to 2 of 2

Count number of cells with different entries

  1. #1
    Registered User
    Join Date
    06-07-2007
    Posts
    3

    Count number of cells with different entries

    Hi
    my proble is simple, but i am new to vba programming so be patient please.

    I have a table with numbers in different rows (kind of stupid remark, since its excel!). The numbers in the rows stand for a product line. As there are several different products in one product line the same number might come up more than once in one row.

    I would now like to count the number of product lines in a coulumn, hence the number of different entries in a column. For example in coulmn J the entries might be: 10 10 10 12 12 12 12 17. I want the makros to display "There are 3 different product lines".

    I tried this
    Sub Test()

    Dim i As Integer
    Dim Anzahl As Integer
    Dim Zahl As Integer

    Zahl = 369490
    Anzahl = 1
    i = 2
    While Not IsEmpty(Cells(10, i))
    If Cells(10, i) = Zahl Then
    i = i + 1
    Else
    Zahl = Zahl + 1
    Anzahl = Anzahl + 1
    End If
    Wend
    MsgBox "Es gib " & Anzahl & " verschiedene Sendungen!"
    End Sub
    but it it says "Error 6: Overflow"

    Any suggestions?

    Thanks!

  2. #2
    Registered User
    Join Date
    06-07-2007
    Posts
    3

    changed Integer to Long

    Ok I kind of found what caused the overflow: The Intger format cant handle the numbers I needed "396054" to "500000" so I changed the format for "Anzahl" and "Zahl" to Long.

    Now everytime I start the function my laptop goes nuts
    I somehow created a never ending loop. I still dont know what to do. Does someboda have a idea to solve my prob.

    Thank you

+ 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