Countif Code

S

Steve

Hi everyone,

I am trying to promt the user with an input box "What column to
count", then use that column to count the number of "Y"s in the
column, and return the number in a message box. Here's what I have so
far:

Sub Count_Yes()

Dim Count_Col As Range

Set Count_Col = Application.InputBox(prompt:= _
"Select Any Cell in Column to Count", Type:=8)
If Count_Col Is Nothing Then
Exit Sub
End If

'Count Function
'Message Box

End Sub

Thanks for any help!
 
G

Gord Dibben

MsgBox WorksheetFunction.CountIf(Count_Col.EntireColumn, "Y")


Gord Dibben MS Excel MVP
 
M

muddan madhu

Sub Count_Yes()
Dim R As Integer
On Error Resume Next
With Application
R = .InputBox("Select Any Cell in Column to Count",
Type:=8).Column
If R <> 0 Then MsgBox .WorksheetFunction.CountIf(Columns(R), "Y")
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top