I would like to know how i can put in a variable the first 8 (or whatever the number) characters of a string in a range on Excel macro.
I have this code but I don't find how to get a certain number of characters on those ranges.
sourceBook.Sheets(1).Name = sourceBook.Sheets(1).Range("first_name") & " - " & sourceBook.Sheets(1).Range("last_name")
CodePudding user response:
Use the Left function e.g.
Public Function func(s As String, n As Integer) As String
'returns the first n characters of a string
func = Left$(s, n)
End Function