[英]String comparison VBA
我试图完成一个范围和它左边的单元格之间的字符串比较。 因此它经过一个范围,查看一个单元格,将值右移并进行比较。 最终目标是使用所有匹配的值填充数组。
我遇到的问题是当我使用debug.print时,字符串的确匹配。 但是我使用的StrComp评估结果为false。
Sub FilterProdType()
'Get the product filter chosen and set to a variable
Dim bArray As Variant
Dim search, cell As Range
Dim prod, item As String
Set search = Sheet2.Range("B2:B41")
For Each cell In search
prod = Sheet1.Range("PRODTYPE").Value
item = cell.Offset(0, 1).Value
Debug.Print ("Value in range 'B2:B41':" & prod)
Debug.Print ("Value in cell directly left one column:" & item)
MsgBox StrComp(item, prod) = 0
Next cell
End Sub
提前致谢!
在我看来,您正在将一个item
如String
与一个prod
如Variant
,因为您在变量声明中确实感到困惑。
你会补充吗
Option Explicit
在顶部,您是否看到您的代码需要
Dim search As Range, cell As Range
Dim prod As String, item As String
...这是Excel-VBA,而不是VB。
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.