LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Countif result in message box

Hi M3Cobb.

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim myCol As Collection
Dim Arr() As Variant
Dim rCell As Range
Dim rng As Range
Dim i As Long
Dim iLRow As Long
Dim msg As String

Set WB = ThisWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

iLRow = SH.Cells(Rows.Count, "A").End(xlUp).Row
Set rng = SH.Range("A2:A" & iLRow)

Set myCol = New Collection

For Each rCell In rng.Cells
If Not IsEmpty(rCell.Value) Then
On Error Resume Next
myCol.Add rCell.Value, CStr(rCell.Value)
On Error GoTo 0
End If
Next rCell
On Error Resume Next

ReDim Arr(1 To myCol.Count, 1 To 2)

For i = LBound(Arr, 1) To UBound(Arr, 1)
Arr(i, 1) = myCol.Item(i)
Arr(i, 2) = Application.WorksheetFunction.CountIf(rng, Arr(i, 1))
Next i

For i = LBound(Arr, 1) To UBound(Arr, 1)
msg = msg & Arr(i, 1) & vbTab & Arr(i, 2) & vbNewLine
Next i
On Error GoTo 0
MsgBox msg, , "Unique Values"
End Sub
'<<=============


---
Regards,
Norman



"M3Cobb" wrote in
message ...

I've got a list of data that i frequently refer to.
What i want to do is to have a macro that will do a countif function
and then show the results in a message box:

Apples = 5
pears = 2
oranges = 4

thanks


--
M3Cobb
------------------------------------------------------------------------
M3Cobb's Profile:
http://www.excelforum.com/member.php...o&userid=24986
View this thread: http://www.excelforum.com/showthread...hreadid=550918



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Countif result problem CindyW Excel Discussion (Misc queries) 4 April 7th 10 03:09 PM
How to get result by using CountIF, if there are 3 conditions to b Subbu Excel Worksheet Functions 4 July 6th 08 11:15 AM
COUNTIF on result of formula Joe M. Excel Discussion (Misc queries) 4 January 4th 08 03:04 PM
Cell formual result change - Message al007 Excel Programming 1 November 15th 05 01:10 PM
popup message if certain criteria met in formula result John Davies Excel Worksheet Functions 0 June 28th 05 10:15 AM


All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"