Results 1 to 3 of 3

Count cells in a dynamic range, calculate their percentage in respect to total cells.

Threaded View

DimitriosNikolouzos Count cells in a dynamic... 02-18-2019, 02:00 PM
TMS Re: Count cells in a dynamic... 02-18-2019, 02:05 PM
banaanas Re: Count cells in a dynamic... 02-24-2019, 11:36 AM
  1. #1
    Registered User
    Join Date
    07-19-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    1

    Count cells in a dynamic range, calculate their percentage in respect to total cells.

    Hi all,

    I'm quite new in programming and i have this question.


    There are 3 columns (from left to right):
    1) IPM Project Name
    2) EAN CODE
    3) Feasibility: each EAN CODE has feasibility right next to it. It could be "Matched", "Matched & Robust" , NA etc

    My code:
    starts from cells(2,1) with rng as Range, moves right until it finds the EAN CODE column and moves downwards, until it finds a cell which is not empty.
    When it does, moves left until it finds the IPM Project name column.


    IPMrng asRange


    What i intend to achieve:
    move down, and for all project names that are the same ( IPMrng.offset(1,0) ), look into the range.offset(0,1) which is the Feasibility column and count how many times "Matched" or "Matched & Robust" categories occur for that IPM Project Name.
    If they occur >50% of the Total categories in the Feasibility column, then type next to it rng.offset(0,2) something like Yes, or No.


    The Count process is not very clear to me and it is definitely wrong. Any help would be highly appreciated.

    Note: I typed rng.select several time to visualize the whole process while stepping through the code. Also added Message Boxes to see how the code works/


    Attachment 611875


    Sub count_test()
    
    Dim datash As Worksheet
    Dim rng As Range, IPMrng As Range
    Dim i As Long
    Dim j As Long
    
    
    Set datash = ActiveSheet
    Set rng = datash.Cells(2, 1)
    rng.Select
    
    
    
    
    Do Until rng.Offset(-1, 0) = "EAN CODE"        'starts from left to right til it finds the right column.
        Set rng = rng.Offset(0, 1)
    
        rng.Select
    
    Loop
    
    Set rng = datash.Cells(2, 14)     'this is the ActiveCell
    
    
    Do Until rng.Offset(0, -1) = ""     'a column on its left
    Set rng = rng.Offset(1, 0)
    
        If rng = "" Then
            
            Set rng = rng.Offset(1, 0)
            rng.Select
            
        Else
            
            ' selects the 1st EAN CODE
            rng.Select
            
            ' setting the range for IPM Project Name
            Set IPMrng = rng.Offset(0, -9)
            IPMrng.Select
            
            i = 0
            j = 0
            
            Do Until IPMrng <> IPMrng.Offset(1, 0)
                    
                Do Until IPMrng = IPMrng.Offset(1, 0) Or IPMrng = IPMrng.Offset(-1, 0)
                                   
                                        'Counts the various Statuses
                        If UCase(ActiveSheet.Cells(rng.Row, rng.Column)) Like "*Matched*" Or UCase(ActiveSheet.Cells(rng.Row, rng.Column)) Like "*Matched & Robust*" Then
                                       
                            i = i + 1
                            MsgBox i
                                
                        Else
                            j = j + 1
                            MsgBox j
                        
                        End If
                            
                Set IPMrng = IPMrng.Offset(1, 0)
                IPMrng.Select
                        
                Loop
                               
            Loop
            
            
                ' Checks if the sum of (Matched + Matched & Robust) is ** Greater Than 50% ** of the total status
                ' If Yes, then Report
                ' If No, then Do not Report
                    
                If i >= 0.5 * j Then
                
                    rng.Offset(0, 3) = "Yes"
                    
                Else
                
                    rng.Offset(0, 3) = "No"
                
                End If
            
            End If
                    
        End If
        
    Loop
    
      
    
    End Sub
    Attached Files Attached Files
    Last edited by DimitriosNikolouzos; 02-19-2019 at 06:27 AM. Reason: added a sample file

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] calculate total based on range of cells / serial number data
    By jilaba in forum Excel General
    Replies: 7
    Last Post: 02-27-2017, 10:38 AM
  2. Percentage/today/range of cells/including empty cells
    By pgohlke in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 11-28-2016, 09:08 PM
  3. Replies: 2
    Last Post: 11-04-2016, 04:56 AM
  4. Replies: 10
    Last Post: 08-12-2014, 07:48 AM
  5. [SOLVED] Formula/Function Required to Count Blank Cells in a Dynamic Range
    By MattyD89 in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 07-14-2014, 04:30 AM
  6. Replies: 4
    Last Post: 01-17-2013, 01:23 PM
  7. [SOLVED] Need to calculate a total from a range of cells on different sheets
    By jrosko1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-22-2012, 12:35 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