[英]vba excel partial string search
With Worksheets("Sheet2")
NewRow = .Range("C" & Rows.Count).End(xlUp).Row + 1
.Range("A" & NewRow) = ws.Range("A91")
.Range("B" & NewRow) = ws.Range("A92")
If ws.Range("A93") = "LN:" & Then
.Range("C" & NewRow) = ws.Range("A94")
Else
.Range("C" & NewRow) = ws.Range("A93")
End If
End With
How can I change that line: 如何更改该行:
If ws.Range("A93") = "LN:" & Then
Code should copy cell A94 if text in cell A93 starts with: LN: regardless what characters are following LN: 如果单元格A93中的文本以以下字符开头,则代码应复制单元格A94: LN:无论LN之后是什么字符:
You can use the VBA LEFT()
string function: 您可以使用VBA
LEFT()
字符串函数:
If Left(ws.range("A93").value, 3) = "LN:" Then
That will take the 3 leftmost characters of the range's value and compare it to the string "LN:" 这将采用范围值的最左边3个字符,并将其与字符串“ LN:”进行比较
另一种选择是将Like运算符与通配符一起使用
If ws.Range("A93") Like "LN:*" & Then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.