Hi Paul
What do you mean by "Input Box" ?
Dave
OzGrid Business Applications
Try putting this into a commandbutton... I bet Dave has a cleaner way.
Private Sub CommandButton1_Click()
Dim MyVar As String
Dim MyAns As Variant
Dim LastRow As Integer
Dim X As Integer
Dim Y As Integer
Y = 0
MyVar = Application.InputBox("What are you looking for?")
LastRow = Range("A65536").End(xlUp).Row
For X = 1 To LastRow
If Range("B" & X).Value = MyVar Then 'Change B to correct column
Y = Y + 1
End If
Next X
If Y = 1 Then
MsgBox Y & " occurrence"
Else
MsgBox Y & " occurrences"
End If
End Sub
e.g. Application.InputBox("Your name", _
"Name", , , , , 2)
Next X MsgBox Y & " occurrence" Else MsgBox Y & " occurrences"
Thanks to Bj I now understand! here is another method:
Sub CellContents()
'Writtent By OzGrid Business Applications
'www.ozgrid.com
'Finds and Displays what is entered into input box
Dim Reply As String, Answer As String
Reply = InputBox("What are you looking for in Column " _
& ActiveCell.Column, "Find and Count")
If Reply = "" Then Exit Sub
Answer = WorksheetFunction.CountIf(ActiveCell.EntireColumn, Reply)
MsgBox "There are " & Answer & " occurences of " _
& Reply & " in Column " & ActiveCell.Column, vbInformation
End Sub
Dave
OzGrid Business Applications