VBA remove first character only if its a letter

kevin440red

New Member
Joined
May 23, 2011
Messages
26
Office Version
  1. 2019
I have this VAB that removes the first character it work well but I need to edit it to where it only removes the first character only if its a letter.
It is set to range.

VBA Code:
Sub RemoveFirstThreeCharactersInEachCell()
For Each cell In Range("b6", Range("b1500").End(xlUp))
If Not IsEmpty(cell) Then
cell.Value = Right(cell, Len(cell) - 1)
End If

Next cell


For Each cell In Range("c6", Range("c1500").End(xlUp))
If Not IsEmpty(cell) Then
cell.Value = Right(cell, Len(cell) - 1)
End If

Next cell

For Each cell In Range("d6", Range("d1500").End(xlUp))
If Not IsEmpty(cell) Then
cell.Value = Right(cell, Len(cell) - 1)
End If

Next cell

For Each cell In Range("e6", Range("e1500").End(xlUp))
If Not IsEmpty(cell) Then
cell.Value = Right(cell, Len(cell) - 1)
End If

Next cell


Columns("A:E").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False



End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try this:

VBA Code:
If Not IsEmpty(cell) Then
    If Left(Cell.Value, 1) Like "[a-zA-Z]" Then
        cell.Value = Mid(cell.Value, 2)
    End If
End If

in 4 places.
 
Upvote 0
Solution
Hello Kevin440red,
format lines in For Each statement like this...
VBA Code:
     If Not IsEmpty(cell) And Not IsNumeric(Left(cell, 1)) Then
        cell.Value = Right(cell, Len(cell) - 1)
    End If
 
Upvote 0
Since your range is fixed and contiguous, this one-liner macro will remove the first character if that character is not a number...
VBA Code:
Sub RemoveFirstAlphaOnly()
  [B6:E1500] = [IF({1},MID(B6:E1500,2-ISNUMBER(-LEFT(B6:E1500)),99))]
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top