excel vba在其他字符中查找属性
问题描述:
在代码中,我想在工作表中找到特定值的列号,并且该值几乎每天都会改变。有时它会包含“İ”,“Ş”,“#”和其他员工等字符。excel vba在其他字符中查找属性
问题是,查找属性不适用于这些字母,我无法获得单元格列号。
这里是我试图找到的位置的代码;
For x = 2 To LastRowB
Set xr = Worksheets("Check").Range("T" & x & ":BQ" & x & "").Find(Check_Value)
If Not (xr Is Nothing) Then
Dim xa As String
xa = Split(xr.Address, "$")
xCheck_Column = xa(1) + 1
xTotal_First = Worksheets("Check").Cells(x, xCheck_Column).Value
e = e + xTotal_First
End If
Next x
在调试模式下,我看到Check_Value没有正确显示。它应该与其他人物,如S和I,但它作为S和I.
编辑:
与改变Check_Value这样;
Dim Check_Value As String
Dim xr As Range
Check_Value = Worksheets("Check_Test").Range("P5").Value
Set xr = Worksheets("Check").Range(""T" & x & ":BQ" & x & "").Find(Check_Value)
Dim xa As Long
xa = xr.Column
我仍然无法获得列值。
答
而不是
Dim xa As String
xa = Split(xr.Address, "$")
xCheck_Column = xa(1) + 1
使用
Dim xa As long
xa = xr.Column
xCheck_Column = xa + 1
或
Dim xa
xa = Split(xr.Address, "$")
xCheck_Column = xa(2) + 1
编辑:
当我使用下面的代码时,我得到了期望的结果。见图片。
Sub t()
Dim rng As Range
Dim str As String
str = "SOY" & ChrW(304) & "S"
Set rng = Range("A1:O10").Find(str)
MsgBox "Column no. " & rng.Column
End Sub
编辑2:我能够从片获得的str
值,然后找到。见下文。
Sub test()
Dim rng As Range
Dim str As String
str = Range("A1").Value
Set rng = Range("D1:O10").Find(str)
MsgBox "Column no. " & rng.Column
End Sub
非常感谢。但是这里的主要问题是,找到财产并不好。在调试模式下,我可以看到它来自xr =无。但我知道它应该带来价值。 – Bildircin13
@ Bildircin13 - 您如何从表格或代码中为'Check_Value'赋值? – Mrig
现在,因为我正在尝试编写代码,所以这个值在代码中。它被写成SOY“&ChrW(304)&”S“,所以它叫喊来像”SOYİS“,但在找到价值,它来作为”SOYIS“,所以它没有找到工作表中的SOYIS值 – Bildircin13