如何比较单元格文本和字符串?

时间:2017-07-06 17:01:53

标签: excel string vba excel-vba

如何将单元格中的文本与字符串进行比较?我想知道一个简单而直接的方法,因为我在下面的方式不计算ABC的重复次数。

ABC这个词在Excel中是C17。

谢谢,

Sub MediaFornecedores()


Dim counter As Integer
Dim i As Integer
Dim ABC As String


i = 14
counter = 0

Do While i < 5

    If UCase(Cells(i, 3)) = "ABC" Then
        counter = counter + 1
    End If

i = i + 1
Loop

Debug.Print counter

End Sub

1 个答案:

答案 0 :(得分:1)

这里应该有一些声明......

Dim i As Integer
Dim test As String
Dim counter As Integer

Set i = 1
Set counter = 0
Set test = "ABC"

Do While i < 5
    If ActiveWorksheet.Cells(i, 3) = test Then
        counter = counter + 1
    End If
    i = i + 1
Loop