PDA

View Full Version : Trim in VBA



anthony20069
10-07-2008, 08:06 AM
Hi guys,

Need some help please....

I have the following code:

Sheets(1).name = "Workflow_" & Worksheets(1).Range("Project").Value

If the Range Project + the wording Workflow_ is longer than 31 Char, i would like the sheet name to have the following:

Workflow_[partofthename]...(with those dots- looks nice :) )

Cant figure out how to trim in VBA.

Thanks for your help

Regards

Anthony

CreganTur
10-07-2008, 08:09 AM
Well the Trim function in VBA only trims away whitespace. What you can use is the Left function.

If Len(Sheets(1).Name) > 31 Then
Sheets(1).Name = Left(Sheets(1).Name,31)
End If

Bob Phillips
10-07-2008, 09:28 AM
Dim fName As String

fName = "Workflow_" & Worksheets(1).Range("Project").Value
If Len(fName) > 31 Then

fName = Left(fName, 28) & "..."
End If
Sheets(1).Name = fName