Function getprice(Matrix As Range, name As String)
Dim i As Integer
Dim row As Variant
Dim col As Variant
Dim price As Variant
'loop to finde inside the range the name im looking for
For i = 1 To Matrix.Rows.Count
If Matrix.Cells(i, 1).Value = name Then
row = Matrix.Cells(i, 1).Address(RowAbsolute:=True)
col = Matrix.Cells(i, 1).Address(ColumnAbsolute:=True)
price = Tabelle2.Cells(row, col + 1).Value
Exit For
Next
getprice = price
End Function
Private Sub cbschaltung_Change()
Dim go As Range
Dim handle As String
'from here it builds the name i.e. EngineMercedesDiesel an there is a Named range with the same titel outside VBA
teil = Range("A4").Value
hersteller = Range("B3").Value
handle = cbschaltung.Value
If checkboxel.Value = True Then
c = checkboxel.Caption
Set go = teil & hersteller & c 'storing to the variable go, here ocures the error
Tabelle3.Range("C4").Value = getprice(go, handle)
ElseIf checkboxmech.Value = True Then
c = checkboxmech.Caption
Set go = teil & hersteller & c
Tabelle3.Range("C4").Value = getprice(go, handle)
End If
End Sub
如何在上面的代码中包含一个点和连字符? 我知道如何在代码中添加点或连字符if if-yes-then-if-then-else。这段代码是if-no-then-if-then-else(如果你有我想说的话)
答案 0 :(得分:6)
hyphen
不如果是第一个或最后,则需要进行转义人物类
如果在字符类 dot
内,[]
也不需要转义,例如:
/[^a-z.0-9-]/i
备注:强>
字符类中的元字符是:
^ (negation)
- (range)
] (end of the class)
\ (escape char)
答案 1 :(得分:2)
连字符已经在那里,只需使用\.
添加转义点。
/ edit:但正如评论中所指出的那样,逃避并不是必需的。
答案 2 :(得分:0)
假设你正在谈论正则表达式,你可以用斜杠\
来逃避。
/[^a-z\.\-0-9]/i
答案 3 :(得分:0)
如果连字符是Regex组中的 last 字符,则不需要转义连字符。但是点应该总是被转义,所以
'/[^a-z\.0-9-]/i'
将按顺序检查 a到z ,。, 0到9 和 - 不区分大小写。