Hi Tony
The code from the earlier post was intended to remove excess blanks between text in addition to any leading or trailing blanks. It would be bit of an over kill if all you need to do is remove leading and trailing spaces, in which case using the Trim function as suggested / posted by Skip and uberpudge would be your best bet. If your still intent on using the code from that earlier posting you should refer back to that thread to view / understand a code correction (it was mistakingly inserting a leading space). Also as suggested by Skip and uberpudge adjust the code to use Long for the Row variable (A habit I should get in to).
In regards to having the user enter a column number or letter, I am wondering if you could simply have the user select a column (click on the column) and then capture and send the column number into the the trimming routine (Which ever one you use).
example:
Sub Button1_Click()
Dim lngCol As Long
Dim lngPrompt As Long
lngCol = ActiveCell.Column
lngPrompt = MsgBox("This will trim all text under column " _
& lngCol & ". Continue ?", vbYesNo + vbQuestion, "Trim ?"
If lngPrompt = vbYes Then
SampleCode lngCol
End If
End Sub
Sub SampleCode(lngCol As Long)
Dim lngRow As Integer 'Row Number
Dim strWS As String 'Worksheet Name
Dim strName As String 'full name field
Dim strSearchChar As String
Dim intPos As Integer 'Pos of Blank in strName
Dim strTemp As String 'rebuild strName
strSearchChar = " "
intCol = 1 'Column A
strWS = "Sheet1"
For lngRow = 1 To 18922 'Row Numbers to loop through
strTemp = ""
strName = Trim(Sheets(strWS).Cells(lngRow, intCol).Value)
Do
'Find position of 1st blank in strName
intPos = InStr(1, strName, strSearchChar, 1)
If intPos <> 0 Then
'strTemp = strTemp & " " & Left(strName, intPos - 1)
strTemp = strTemp & Left(strName, intPos)
strName = Trim(Right(strName, Len(strName) - intPos))
Else
strTemp = strTemp & Trim(strName)
End If
Loop Until intPos = 0
'MsgBox strTemp
Sheets(strWS).Cells(lngRow, intCol).Value = strTemp
Next lngRow
End Sub