Results 1 to 24 of 24

Count distinct values that correspond to a criteria

Threaded View

  1. #1
    Registered User
    Join Date
    08-30-2005
    Posts
    67

    Count distinct values that correspond to a criteria

    Hi,

    I have a list of Customer and Items they have ordered.

    I have this code that counts how many orders have been placed for 2 specific items (TBA and 8IM) and places the value in worksheet List cell A1:

    Sub CountItems()
    Dim wsd As Worksheet, wsc As Worksheet
    Dim Lastrow As Long, i As Long, J As Long
    Dim Cell As Range
    
    Set wsc = Sheets("List")
    Set wsd = Sheets("Jan")
    
    i = 0
    
    Application.ScreenUpdating = False
    
    With wsd
        Lastrow = .Range("B" & Rows.Count).End(xlUp).Row
        For Each Cell In .Range("B2:B" & Lastrow)
            If Cell = "TBA" Or Cell = "8IM" Then
    i = i + 1
            End If
        Next Cell
    End With
     
    With wsc
        .Range("A1").Value = i
    
    End With
    
    Application.ScreenUpdating = True
    
    End Sub
    I would need some suggestions how to amend this code to count how many Customers have ordered either item TBA or item 8IM. If a Customer ordered at least once any of these items it has to be counted as 1.

    Thanks,
    Eduard
    Attached Files Attached Files

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