VBA to display count in a message box. xl 2003

joe.muckle

Board Regular
Joined
Oct 19, 2010
Messages
132
Hi Guru's

Does any one know how to get excel to diplay a count for certain values in a message box??

Ideally I would want the message box to contain two answers (two seperate counts).

Thanks in advance.
Joe.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try like this

Code:
Sub test()
Dim x As Long, y As Long
x = 4
y = 1000
MsgBox "X =" & vbTab & x & vbNewLine & "Y =" & vbTab & y
End Sub
 
Upvote 0
Not much to go on, but basically:
Code:
Msgbox "Count one: " & count1 & vbcrlf & "Count two: " & count2
 
Upvote 0
Hi,

Assuming your values are numerical try this UDF:

Code:
Function countVals(valRng As Range, valCount As Integer)
    Dim cell As Object
    Dim valResult As Integer
    
    For Each cell In valRng
        If cell.Value = valCount Then valResult = valResult + 1
    Next
    
    countVals = valResult
    MsgBox countVals
End Function

Then in your sheet type:

=countVals(F1:F25,2) - Count how many 2's are in the range F1 to F25.
 
Upvote 0
Sorry if I was a bit vague, I have a column which has two answers (say x & y) what I want is VBA to count the occurances of each answer and then display them in a message box.

Joe.
 
Upvote 0
Sorry, I was meant to add that the values I want to count are actually answers to formulas.

Does this make a difference??

Thanks again.
 
Upvote 0
Solved this with:

Code:
Sub count()
Dim count As Integer
Dim count1 As Integer
Worksheets("Non - Workflow").Select
Dim LR As Long, i As Long
count = 0
LR = Range("A" & Rows.count).End(xlUp).Row
For i = LR To 2 Step -1
    If Range("O" & i).Value = "Not RTV" Then
    count = count + 1
    
    End If
Next i
Dim L As Long, j As Long
count1 = 0
LT = Range("A" & Rows.count).End(xlUp).Row
For j = LT To 2 Step -1
   If Not Range("O" & j).Value = "Not RTV" Then
    count1 = count1 + 1
    
   End If
Next j
Worksheets("Home").Select
MsgBox count1 & " RTV task(s) counted and  " _
& count & " Non RTV task(s) counted"
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top