用VBA统计出excel单元格区域A5:C20公式中含“车间”的单元格个数,如何编写?
1个回答
展开全部
建立一个宏,或一个按钮输入以下代码就行了
d = 0
With ActiveSheet.Range("a5:c20")
Set c = .Find("车间", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
d = d + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
msgbox d
第二种代码:
Dim b As Range
c = 0
With ActiveSheet.Range("a5:c20")
For Each b In Range("a5:c20")
Set d = b.Find("车间", LookIn:=xlValues)
If Not d Is Nothing Then
c = c + 1
End If
Next
End With
MsgBox c
太多方法了,提供两种供你。
d = 0
With ActiveSheet.Range("a5:c20")
Set c = .Find("车间", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
d = d + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
msgbox d
第二种代码:
Dim b As Range
c = 0
With ActiveSheet.Range("a5:c20")
For Each b In Range("a5:c20")
Set d = b.Find("车间", LookIn:=xlValues)
If Not d Is Nothing Then
c = c + 1
End If
Next
End With
MsgBox c
太多方法了,提供两种供你。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询