Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Trim special charcters from start of string

Is there a function or quick VBA routine that will remove and CHR(10)
or CHR(13) characters from the begining of a string.

If not, how about someway to find the first non-special character in a
string?

Thanks for the help.

- John

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Trim special charcters from start of string

Try Excels CLEAN function

strTemp = application.clean(strTemp)



"John Michl" wrote:

Is there a function or quick VBA routine that will remove and CHR(10)
or CHR(13) characters from the begining of a string.

If not, how about someway to find the first non-special character in a
string?

Thanks for the help.

- John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Trim special charcters from start of string

Thanks. That almost works. I only want to remove those characters if
they are before the first real text in a string. Using CLEAN on my
string eliminates all of the carriage returns later on the string that
I want to keep. Something like LTRIM would be perfect but there
doesn't seem to be a LCLEAN.

What I'm trying to do is retrieve text from a text box that has been
edited by the user. I need someway to determine what position contains
the first non-special character (i.e., real text) so that I can start
the retrieval at that point.

- John

JMB wrote:
Try Excels CLEAN function

strTemp = application.clean(strTemp)



"John Michl" wrote:

Is there a function or quick VBA routine that will remove and CHR(10)
or CHR(13) characters from the begining of a string.

If not, how about someway to find the first non-special character in a
string?

Thanks for the help.

- John



  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Trim special charcters from start of string

Maybe something like this would work better. Select the cells and run. Just
be sure to keep a backup of your data.

Sub test()
Dim strTemp As String
Dim i As Long
Dim rngCell As Range

For Each rngCell In Selection.Cells
If Not IsEmpty(rngCell) Then
strTemp = rngCell.Value
For i = 1 To Len(strTemp)
If Asc(Mid(strTemp, i, 1)) < 10 And _
Asc(Mid(strTemp, i, 1)) < 13 Then
strTemp = Right(strTemp, Len(strTemp) - i + 1)
Exit For
End If
Next i
rngCell.Value = strTemp
End If
Next rngCell

End Sub



"John Michl" wrote:

Thanks. That almost works. I only want to remove those characters if
they are before the first real text in a string. Using CLEAN on my
string eliminates all of the carriage returns later on the string that
I want to keep. Something like LTRIM would be perfect but there
doesn't seem to be a LCLEAN.

What I'm trying to do is retrieve text from a text box that has been
edited by the user. I need someway to determine what position contains
the first non-special character (i.e., real text) so that I can start
the retrieval at that point.

- John

JMB wrote:
Try Excels CLEAN function

strTemp = application.clean(strTemp)



"John Michl" wrote:

Is there a function or quick VBA routine that will remove and CHR(10)
or CHR(13) characters from the begining of a string.

If not, how about someway to find the first non-special character in a
string?

Thanks for the help.

- John




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Trim special charcters from start of string

If the characters are in the other order than you specified, i.e. Chr(13)
then Chr(10) (CarriageReturn/LineFeed) you can do this

Do While Left(MyStr, 2) = vbCrLf
MyStr = Mid(MyStr, 3)
Loop


"John Michl" wrote:

Thanks. That almost works. I only want to remove those characters if
they are before the first real text in a string. Using CLEAN on my
string eliminates all of the carriage returns later on the string that
I want to keep. Something like LTRIM would be perfect but there
doesn't seem to be a LCLEAN.

What I'm trying to do is retrieve text from a text box that has been
edited by the user. I need someway to determine what position contains
the first non-special character (i.e., real text) so that I can start
the retrieval at that point.

- John

JMB wrote:
Try Excels CLEAN function

strTemp = application.clean(strTemp)



"John Michl" wrote:

Is there a function or quick VBA routine that will remove and CHR(10)
or CHR(13) characters from the begining of a string.

If not, how about someway to find the first non-special character in a
string?

Thanks for the help.

- John






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Trim special charcters from start of string

Thanks for the help Charlie and JMB.

My application is used to retrieve the contents of user edited text
boxes and strip out the early CR entered with the "Enter" key. I
played around with your ideas and came up with the following that
identifies the first non-CR character in the text box.

Sub FindNonCR
Dim shp As Shape
Set shp = Sheets("Assumptions").Shapes("tbNote_Test")
l = shp.TextFrame.Characters.Count

i = 1

Do While shp.TextFrame.Characters(Start:=i, Length:=1).Text = Chr(10)
If shp.TextFrame.Characters(Start:=i, Length:=1).Text = Chr(10)
Then
MsgBox "Position " & i & " is CRLF"
Else
MsgBox "Position " & i & " is " &
shp.TextFrame.Characters(Start:=i, Length:=1).Text
End If
i = i + 1
Loop

MsgBox "First non-CR is at position " & i

End Sub

For my actual app I'll only need the value (not the message boxes).

- John

Charlie wrote:
If the characters are in the other order than you specified, i.e. Chr(13)
then Chr(10) (CarriageReturn/LineFeed) you can do this

Do While Left(MyStr, 2) = vbCrLf
MyStr = Mid(MyStr, 3)
Loop


"John Michl" wrote:

Thanks. That almost works. I only want to remove those characters if
they are before the first real text in a string. Using CLEAN on my
string eliminates all of the carriage returns later on the string that
I want to keep. Something like LTRIM would be perfect but there
doesn't seem to be a LCLEAN.

What I'm trying to do is retrieve text from a text box that has been
edited by the user. I need someway to determine what position contains
the first non-special character (i.e., real text) so that I can start
the retrieval at that point.

- John

JMB wrote:
Try Excels CLEAN function

strTemp = application.clean(strTemp)



"John Michl" wrote:

Is there a function or quick VBA routine that will remove and CHR(10)
or CHR(13) characters from the begining of a string.

If not, how about someway to find the first non-special character in a
string?

Thanks for the help.

- John





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trim out last seven characters from a string... DubboPete Excel Discussion (Misc queries) 3 February 2nd 10 05:16 AM
Start macro at a special time Sean Excel Programming 0 February 4th 06 02:10 PM
trim a string by specific number of characters windyoldman Excel Discussion (Misc queries) 2 July 13th 05 01:53 PM
Trim string vII Jesse Hamilton[_2_] Excel Programming 2 November 10th 03 08:43 PM
Trim Special Characters (Japanese Environment) Neeru Excel Programming 0 November 3rd 03 07:40 AM


All times are GMT +1. The time now is 08:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"