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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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