+ Reply to Thread
Results 1 to 1 of 1

Error in Cell Counting

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2014
    Location
    San Francisco, CA
    MS-Off Ver
    2013
    Posts
    24

    Error in Cell Counting

    Hello,

    I'm hoping to receive some help for a code I've been using that is suddenly working very strangely. Attached is an example workbook and below is the code I've been using to format it. The code alphabetizes and counts the number of entries for a given 'FC4' code and then deletes the duplicates. However, now it seems to be incorrectly counting some lines.

    For example in the attached example workbook, you can 'manually' count 2741 entries for the CHA117 entry. However, my code is counting that entry to be 2746.

    The peculiar thing is that the code does seem to count some entries correctly, but on other lines it spits out an inaccurate count (the inaccurate count is always higher than the accurate count).

    I think my problem must be with my SUMIF function, but I can't figure it out properly...

    Any thoughts/advice would be greatly appreciated!

    Thank you!

    Sub Complaint_Format()
    
    'Alphabetize entries by caller code
       On Error Resume Next
        
         If Not Intersect(Target, Range("J:J")) Is Nothing Then
            Range("J2").Sort Key1:=Range("J3"), _
              Order1:=xlAscending, Header:=xlYes, _
              OrderCustom:=1, MatchCase:=False, _
              Orientation:=xlTopToBottom
        End If
            
    Dim LR As Long
    
    With ActiveSheet
    
    'delete unused information
    LR = .Cells(Rows.Count, 1).End(xlUp).Row
        .Columns("G").Delete
        .Columns("A:C").Delete
        
    'convert to text to columns for calculations
        .Columns("G").TextToColumns
        
    'Add number of times each complainant complained
    'Create total for each complainant
        .Range("H2").Formula = "=SUMIF($F$2:$F$" & LR & ",F2,$G$2:$G$" & LR & ")"
        .Range("H2").AutoFill .Range("H2:H" & LR)
    
    'Record calculations in new column
        .Columns("H").Copy
        .Columns("H").PasteSpecial xlValues
        
        .Range("H1").Value = "Number of Complaints"
        
    'Remove duplicate complaints
        .Range("A1:H" & LR).RemoveDuplicates 6, xlYes
    
    'Remove excess information
        .Columns("G").Delete
    
    'Autofit columns
        .Columns("A:G").AutoFit
       
    End With
    
    'name worksheet
    ActiveSheet.Name = "COMPLAINTS FORMATTED"
    
    End Sub
    Attached Files Attached Files

+ 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. [SOLVED] Error 91 when counting and adding commandButton
    By selector in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2014, 10:24 AM
  2. [SOLVED] Counting Rows in a Table error
    By greggpetersen75 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2013, 02:41 PM
  3. [SOLVED] getting error on simple counting formula
    By awest181 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-27-2012, 06:08 PM
  4. Error counting words in cell when there are zero
    By GenieNitro in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-15-2008, 03:40 PM
  5. counting error
    By leem in forum Excel General
    Replies: 5
    Last Post: 04-07-2007, 07: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