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
Bookmarks