+ Reply to Thread
Results 1 to 9 of 9

MACRO - Count items in column and display the result

Hybrid View

stalin1107@gmail.com MACRO - Count items in column... 08-22-2013, 12:15 AM
humdingaling Re: MACRO - Count items in... 08-22-2013, 12:31 AM
stalin1107@gmail.com Re: MACRO - Count items in... 08-22-2013, 12:52 AM
humdingaling Re: MACRO - Count items in... 08-22-2013, 02:18 AM
stalin1107@gmail.com Re: MACRO - Count items in... 08-22-2013, 02:55 AM
humdingaling Re: MACRO - Count items in... 08-22-2013, 04:12 AM
stalin1107@gmail.com Re: MACRO - Count items in... 09-02-2013, 06:42 AM
humdingaling Re: MACRO - Count items in... 09-02-2013, 09:23 PM
jindon Re: MACRO - Count items in... 09-02-2013, 10:45 PM
  1. #1
    Registered User
    Join Date
    08-22-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    MACRO - Count items in column and display the result

    From above Title you may think its easy. But for me it is not. I am struggling in this. It will be much appreciated if anyone solve this.

    I have attahed my sample data.I need a MACRO

    In this , I need a code to check the 'E' column and pop up should be displayed with the number of Duplicate values (If any duplicates found)
    Eg., Duplicate values found = 4

    Also One pop up should take the Status column - 'G' and should return the number of values depend on the status. It should return the below mentioned details in same pop up(Along with duplicate values).
    Eg., Closed = 5
    Open = 5
    Waiting =3
    Reopen = 57
    Assigned = 65

    It depends. But the value of status (eg.,Assigned, Reopen) may varry.The status may be any thing.

    Please help me to sort this thing SampleExcel.xlsx

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: MACRO - Count items in column and display the result

    do you really need macro for what you are doing
    sounds like a countif formula would do the job

    if you just hide the helper countif table and pop up form with labels pointing those cells
    Attached Files Attached Files
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    08-22-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: MACRO - Count items in column and display the result

    Its nice...But I need only MACRO boss. Because I have to merge this with a tool which have several MACRO modules

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: MACRO - Count items in column and display the result

    that is fine
    can you work with helper table?
    would just make it easier to code

    Try this macro

    Sub status()
    '
    ' Status Macro
        Dim status As String
        Dim J As Integer
        
        For J = 2 To 8
            status = status & Range("l" & J).Value & " = " & Range("M" & J).Value & vbNewLine
                 
        Next J
        
        MsgBox status
        
    
    End Sub
    ps with the countif formula maybe extend it to read the whole column if data set is changing
    =COUNTIF($G:$G,L2)
    Attached Files Attached Files
    Last edited by humdingaling; 08-22-2013 at 02:27 AM.

  5. #5
    Registered User
    Join Date
    08-22-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: MACRO - Count items in column and display the result

    Sorry Its not working It shows only '=' nothing else. I have copy pasted the Macro in another MACRO? Is any prob in that? Also I have used columns till Z. This code is working fine for sample data but not working there boss...Pls help
    Last edited by stalin1107@gmail.com; 08-22-2013 at 03:35 AM.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: MACRO - Count items in column and display the result

    that is why i asked if it can work with the helper table which has the countif calculations on the sheet itself

    Try Version 2

    Sub StatusV2()
        
       Dim Count, lRow, Closed, failed, pending, waiting, resolving, assigned, validation As Integer
       
       Count = 2
       lRow = Range("G65536").End(xlUp).Row
       
        For Count = 2 To lRow
        Select Case Range("G" & Count)
            Case "Closed"
            Closed = Closed + 1
            
            Case "Failed"
            failed = failed + 1
            
            Case "Pending"
            pending = pending + 1
            
            Case "Waiting"
            waiting = waiting + 1
            
            Case "Resolving"
            resolving = resolving + 1
            
            Case "Assigned"
            assigned = assigned + 1
            
            Case "Validation"
            validation = validation + 1
            
        End Select
        
        Next Count
        
        MsgBox ("Closed = " & Closed & vbNewLine & "Failed = " & failed & vbNewLine & "Pending = " & pending & vbNewLine & "waiting = " & waiting & vbNewLine _
                & "resolving = " & resolving & vbNewLine & "assigned = " & assigned & vbNewLine & "validation = " & validation & vbNewLine)
        
        
    End Sub
    problem with this code is that status is static
    Attached Files Attached Files
    Last edited by humdingaling; 08-22-2013 at 04:15 AM.

  7. #7
    Registered User
    Join Date
    08-22-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: MACRO - Count items in column and display the result

    Sorry its not working for me. If the columns J to n will have values that data while copying to another sheet , it is also giving the status data.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: MACRO - Count items in column and display the result

    are you running V2?

    v2 does not need any data in J to N to run
    runs purely on column G

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: MACRO - Count items in column and display the result

    Try
    Sub test()
        Dim a, i As Long, e, s, msg As String
        a = Cells(1).CurrentRegion.Value
        With CreateObject("Scripting.Dictionary")
            For i = 2 To UBound(a, 1)
                If Not .exists(a(i, 5)) Then
                    Set .Item(a(i, 5)) = _
                    CreateObject("Scripting.Dictionary")
                    .Item(a(i, 5)).CompareMode = 1
                End If
                .Item(a(i, 5))(a(i, 7)) = .Item(a(i, 5))(a(i, 7)) + 1
            Next
            For Each e In .keys
                If (.Item(e).Count = 1) * (.Item(e).items()(0) = 1) Then
                    .Remove e
                End If
            Next
            If .Count > 0 Then
                For i = 0 To .Count - 1
                    For Each s In .items()(i).keys
                        msg = msg & vbLf & s & " = " & .items()(i)(s)
                    Next
                    MsgBox msg, vbInformation, .keys()(i): msg = ""
                    If i <> .Count - 1 Then
                        If MsgBox("Continue?", vbQuestion) <> vbOK Then Exit For
                    End If
                Next
            End If
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. data in 2 column and display the desired result in 3rd column
    By vaz_saz in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 01-02-2013, 05:37 PM
  2. Replies: 9
    Last Post: 07-31-2012, 04:37 PM
  3. Replies: 3
    Last Post: 01-21-2010, 06:58 AM
  4. Need to count items and display summary
    By sharke in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-05-2008, 01:08 PM
  5. Display COUNT result in Titlebar
    By davidemile in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-21-2006, 05:20 PM

Tags for this Thread

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