PDA

View Full Version : Delete character in cell



stefan0901
06-26-2009, 12:42 AM
Hello,

in a certain column (column "K") of my excel sheet I want to delete the (first) letter "A" for all the lines for which this is the case. I have been trying to work out a macro a long time, but he never works, can anybody help me !

Thx,

anandbohra
06-26-2009, 02:30 AM
Try this

Sub remove_space()
Dim yesRay As Range
Dim xVal As Variant

With ThisWorkbook.Worksheets("sheet1")
Set yesRay = Range(.Range("K1"), .Range("K65536").End(xlUp))
End With

For Each xVal In yesRay
xVal.Value = Right(xVal.Value, Len(xVal) - 1)
Next xVal
End Sub


the above code remove first character only
If u want to remove only where first character is A then use this code


Sub remove_space()
Dim yesRay As Range
Dim xVal As Variant

With ThisWorkbook.Worksheets("sheet1")
Set yesRay = Range(.Range("K1"), .Range("K65536").End(xlUp))
End With

For Each xVal In yesRay
If Left(xVal, 1) = "A" Then xVal.Value = Right(xVal.Value, Len(xVal) - 1)
Next xVal
End Sub