我已经尝试编写一个宏,在其中搜索特定文本。A)要搜索的列,B)结果应出现的列和C)正在对其进行搜索的文本所有都由相应的输入框引用。我尝试了各种排列,但无法在下面的代码中替换Y2:Y&LastRow,因此它指的是从输入框中输入的内容来搜索。
代码如下:-
Sub CountIfAllVariablesFromInputBox()
Dim LastRow As Long
Dim ChkColumn As String
'display an input box asking for column
ChkColumn = InputBox( _
"Please enter column to check")
'if no input stop
ColumnNumber = Columns(ChkColumn).Column
If Len(ChkColumn) = 0 Then
MsgBox "No column entered"
Exit Sub
End If
Dim InputColumn As String
'display an input box asking for column
InputColumn = InputBox( _
"Please enter column to insert results")
'if no input stop
If Len(InputColumn) = 0 Then
MsgBox "No column entered"
Exit Sub
End If
'inputbox for text string to search for
Dim SuccessKeyWord As String
SuccessKeyWord = InputBox(Prompt:="Enter KeyWord For Success", _
Title:="KeyWord For Success", Default:="WOW!!")
LastRow = Range(ChkColumn & Rows.Count).End(xlUp).Row
Range(InputColumn & "1").Formula = "=COUNTIF(Range("Y2:Y"&LastRow),""" & SuccessKeyWord & """)"
End With
End Sub
谷歌搜索提供了太多的方式来引用范围(包含单元格,单元格,变量),我感到不知所措,不幸的是,我无法获得任何结果。
非常感谢您的帮助。
我已经发布了screenShot。有时我可能需要在“ W”列中搜索,而在其他地方则要在“ Y”列中搜索。我需要使用输入框来保持这种灵活性。
Error after replacing the last line of the code by:-
Range(InputColumn&“ 1”)。Formula =“ = COUNTIF(Range(”“”“&ChkColumn&2&”:“&ChkColumn&”“&LastRow),”“”&SuccessKeyWord&“”))“
注意:-
在W列中搜索
AA列中的结果
搜索文字!! >>
我已经尝试编写一个宏,在其中搜索特定文本。 A)要搜索的列,B)应在其中显示结果的列,C)要进行搜索的文本...
您的行代码进行了一些修改:
假设您希望用户选择列