I'm trying to make function that makes hyperlink from 2 text fields. Here's the code:
Option Explicit
Sub AddLink()
Dim MyPath
Dim MyChar
Dim i As Integer
Dim myString
Dim numbers
Dim siteID
Dim MyWB
Dim siteAddress
MyPath = "SomeFilePath\"
MyChar = "\"
For i = 2 To 4000 Step 1
myString = Range("B" & i).Value
numbers = myString.TrimStart(MyChar)
siteID = Range("F" & i).Value
MyWB = "WO_" & numbers & "_" & siteID & ".xls"
siteAddress = MyPath & MyWB
ActiveSheet.Hyperlinks.Add Range("B" & i), siteAddress
Next i
End Sub
So I get error on "numbers = myString.TrimStart(MyChar)" - error 424 object required. I'm rly big noob @ vba, could you help me? PS I know that I should define the variable type, but when I do this I get again some f... errors that drives me nuts.
That looks like vb.net not vba. Trim removes spaces. So vba is x = trim(str)
. Maybe use instr
to get position of first backslash thenuse Left
function.