![]() |
Help with Error Messages
Sub RemoveAlphas() '' Remove alpha characters from a string. Dim intI As Integer Dim rngR As Range, rngRR As Range Dim strNotNum As String, strTemp As String[/color][/color] On Error GoTo Endit Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _ xlTextValues) For Each rngR In rngRR strTemp = "" For intI = 1 To Len(rngR.Value) If Mid(rngR.Value, intI, 1) Like "[0-9]" Then strNotNum = Mid(rngR.Value, intI, 1) Else: strNotNum = "" End If strTemp = strTemp & strNotNum Next intI rngR.Value = strTemp Next rngR Endit: masgbox "Cells contain numbers only" End Sub this macro works good but it's correctly being used in the middle of another macro so everything stops. how can i change the error checker to continue with the macro if the cells contain numbers only? I no longer want the msgbox -- Tha BeatMaker ------------------------------------------------------------------------ Tha BeatMaker's Profile: http://www.excelforum.com/member.php...o&userid=23998 View this thread: http://www.excelforum.com/showthread...hreadid=384113 |
Help with Error Messages
Try this procedure please, it might work better for you:
Sub RemoveAlphasNew() '' Remove alpha characters from a string. Dim i As Integer Dim rngR As Range, rngRR As Range On Error Resume Next Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _ xlTextValues) For Each rngR In rngRR.Cells Do While Not IsNumeric(rngR.Value) For i = 1 To 256 Select Case i Case 1 To 42, 45, 46, 48 To 57 'note: 46 is decimal point, you might want to remove it if more than one Case Else rngR.Value = Replace(rngR.Value, Chr$(i), "", 1, -1) End Select Next i Loop Next 'rngR End Sub "Tha BeatMaker" wrote in message news:Tha.BeatMaker.1rkbqb_1120341903.1328@excelfor um-nospam.com... Sub RemoveAlphas() '' Remove alpha characters from a string. Dim intI As Integer Dim rngR As Range, rngRR As Range Dim strNotNum As String, strTemp As String[/color] On Error GoTo Endit Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _ xlTextValues) For Each rngR In rngRR strTemp = "" For intI = 1 To Len(rngR.Value) If Mid(rngR.Value, intI, 1) Like "[0-9]" Then strNotNum = Mid(rngR.Value, intI, 1) Else: strNotNum = "" End If strTemp = strTemp & strNotNum Next intI rngR.Value = strTemp Next rngR Endit: masgbox "Cells contain numbers only" End Sub this macro works good but it's correctly being used in the middle of another macro so everything stops. how can i change the error checker to continue with the macro if the cells contain numbers only? I no longer want the msgbox -- Tha BeatMaker ------------------------------------------------------------------------ Tha BeatMaker's Profile: http://www.excelforum.com/member.php...o&userid=23998 View this thread: http://www.excelforum.com/showthread...hreadid=384113 [/color] |
All times are GMT +1. The time now is 08:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com