Excel: remove text after the first non allowable character
I wish to remove text from a string from the first non-allowable cha开发者_开发问答racter on. I have gotten so far, but now im stuck.
Real Example:
The cells value is: transactions_Label}" showEffect="{showView}" width="100%" height="100%" transactionScreen="true" />
I want the only allowable characters to be 0-9 a-z and underscore _:
The result would be: transactions_Label
Thanks if you can help
Brian
Dont like answering my own question, but this is what I used in VBA:
Sub TrimRight()
mycolumn = "E" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "1:" & mycolumn & LastRow)
For Each c In MyRange
For X = 1 To Len(c.Value)
If Mid(c.Value, X, 1) Like "[!0-9A-Za-z_]" Then
c.Value = Left(c.Value, X - 1)
Exit For
End If
Next
Next
End Sub
精彩评论