Vba 我想计算一行中字符串出现的次数(特定于3列:B、J、K)。
如果字符串出现在所有3列中,则计数应为1,并应开始在下一行中查找字符串 专用子按钮() 我想要一个按钮来获取用于搜索的输入字符串Vba 我想计算一行中字符串出现的次数(特定于3列:B、J、K)。,vba,excel,Vba,Excel,如果字符串出现在所有3列中,则计数应为1,并应开始在下一行中查找字符串 专用子按钮() 我想要一个按钮来获取用于搜索的输入字符串 Dim MyCount As Long MyCount = 0 Dim rng1 As Range Dim i As Integer Dim c As Long Dim rng As Range, cell As Range Set rng = ActiveCell 我想我在活动单元格中有一些错误。我想应该是牢房之类的 此工作簿。激活 设置ws=工作表(“提取”)
Dim MyCount As Long
MyCount = 0
Dim rng1 As Range
Dim i As Integer
Dim c As Long
Dim rng As Range, cell As Range
Set rng = ActiveCell
我想我在活动单元格中有一些错误。我想应该是牢房之类的
此工作簿。激活
设置ws=工作表(“提取”)
与ws
i = 2
MyCount = 0
循环开始了
Do While i < 15506
c = 2
rng = Cells(i, c)
If Not InStr(rng, inputString) = True Then
c = 10
rng = Cells(i, c)
If Not InStr(rng, inputString) = True Then
c = 11
rng = Cells(i, c)
If Not InStr(rng, inputString) = True Then
i = i + 1
Else
MyCount = MyCount + 1
i = i + 1
End If
Else
MyCount = MyCount + 1
i = i + 1
End If
Else
MyCount = MyCount + 1
i = i + 1
End If
Loop
端接头
总行数为:15505。我对VB很陌生。如果有任何新功能,请告诉我。不确定我是否理解正确,但我认为这可能是您正在寻找的:
Sub SO()
Dim cCount As Long, i As Long, inputString As String
inputString = InputBox("Enter Application Name:", "Input Box Text")
cCount = 0
For i = 2 To 15505
If InStr(Cells(i, 2).Value, inputString) > 0 And _
InStr(Cells(i, 10).Value, inputString) > 0 And _
InStr(Cells(i, 11).Value, inputString) > 0 Then cCount = cCount + 1
Next i
MsgBox "Number of matches is: " & cCount
End Sub
有一个简单的公式可以在不使用任何vba的情况下执行此操作:
=COUNTIF(1:1,“*code*”)
,其中code是您要查找的单词,1:1是您要查找的行。感谢您的回复。如果你能再详细一点,再加上解释,我会更高兴的。。我想搜索总共15505行。如何在没有循环的情况下计数您将rng
声明为范围
变量,但您正试图使用它存储字符串
变量。。。
If Not rng1 Is Nothing Then
MsgBox inputData & "has matched and total count is:" & MyCount
Else
MsgBox inputData & " not found"
End If
Sub SO()
Dim cCount As Long, i As Long, inputString As String
inputString = InputBox("Enter Application Name:", "Input Box Text")
cCount = 0
For i = 2 To 15505
If InStr(Cells(i, 2).Value, inputString) > 0 And _
InStr(Cells(i, 10).Value, inputString) > 0 And _
InStr(Cells(i, 11).Value, inputString) > 0 Then cCount = cCount + 1
Next i
MsgBox "Number of matches is: " & cCount
End Sub