Hey everyone! I would like my code (pasted below) to not only count all instances of variable "myValue", but to also count instances of myValue which is generated with formulas. As is, it will only count cells where myValue actually is the value rather than also counting cells where myValue is generated from a formula. Should I be using the cell.Value method with an If statement instead?
Sub String_Counter()
Dim myValue As Variant
Dim Range_To_Search As Range
Dim Search_Variable As Integer
MsgBox ("I will assume you would like to count something on the active sheet")
myValue = InputBox("What range of cells would you like to search? (input must be a continuous range)" & vbNewLine & vbNewLine & "Example:" & vbNewLine & "A1:C45 - This searches all of columns A, B, and cells 1 - 45 of column C" & vbNewLine & vbNewLine & "Example:" & vbNewLine & "A:A - This searches all of column A for a value")
Set Range_To_Search = Range(myValue)
myValue = InputBox("What string or number would you like to count the instances of within your specified range?" & vbNewLine & vbNewLine & "(Type an exact representation of what you wish to search for. Capitalization and spacing matters)")
Search_Variable = Application.WorksheetFunction.CountIf(Range_To_Search, myValue)
MsgBox (myValue & " appears " & Search_Variable & " times within the specified range")
End Sub
Sub String_Counter()
Dim myValue As Variant
Dim Range_To_Search As Range
Dim Search_Variable As Integer
MsgBox ("I will assume you would like to count something on the active sheet")
myValue = InputBox("What range of cells would you like to search? (input must be a continuous range)" & vbNewLine & vbNewLine & "Example:" & vbNewLine & "A1:C45 - This searches all of columns A, B, and cells 1 - 45 of column C" & vbNewLine & vbNewLine & "Example:" & vbNewLine & "A:A - This searches all of column A for a value")
Set Range_To_Search = Range(myValue)
myValue = InputBox("What string or number would you like to count the instances of within your specified range?" & vbNewLine & vbNewLine & "(Type an exact representation of what you wish to search for. Capitalization and spacing matters)")
Search_Variable = Application.WorksheetFunction.CountIf(Range_To_Search, myValue)
MsgBox (myValue & " appears " & Search_Variable & " times within the specified range")
End Sub