This will get all the text behind the last hyphen found:
Function GetRoomNumber(strComputerName) Dim hyphenIndex hyphenIndex = InStrRev(strComputerName, "-") If hyphenIndex > 0 Then GetRoomNumber = Mid(strComputerName, hyphenIndex+1) End If End Function
Use in your example would be:
Dim roomArray(2) roomArray = Array("-1", "-2", "-3") Dim item, index For index = LBound(roomArray) To UBound(roomArray) item = roomArray(index) If ("-" & GetRoomNumber(strComputerName)) = item Then ..do something End If Next
Or the short version will be (without defining a function with data verification):
... If Mid(strComputerName, InStrRev(strComputerName, "-") ) = item Then ...
source share