ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to remove a character from the first index? (https://www.excelbanter.com/excel-discussion-misc-queries/63191-how-remove-character-first-index.html)

dex

How to remove a character from the first index?
 
question: i recorded a macro that involves replacing the character "p"
in the part numbers after I run the macro with a nuLL string ""....but
i want the macro to replace the p only in the first index not anywhere
else in the part number: Here is part of my code.

Columns("A:A").Select
Selection.Find(What:="p", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Selection.Replace What:="p", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Hope this helps.


JAdamJ

How to remove a character from the first index?
 
You could do this with a cell formula. Put the following in the first row of
another column and copy down.

=IF(LEFT(A1,1)="p",RIGHT(A1,LEN(A1)-1),A1)

If you'd rather use a macro, you could loop through each cell and use a
similar formula in vba, but it's not quite as simple. Let us know if you
need the code.

"dex" wrote:

question: i recorded a macro that involves replacing the character "p"
in the part numbers after I run the macro with a nuLL string ""....but
i want the macro to replace the p only in the first index not anywhere
else in the part number: Here is part of my code.

Columns("A:A").Select
Selection.Find(What:="p", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Selection.Replace What:="p", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Hope this helps.



dex

How to remove a character from the first index?
 
Yes i would rather use it in the macro. What is the syntax?


JAdamJ

How to remove a character from the first index?
 
See if this does what you want.

Sub Fordex()
For Each c In Range("A:A")
If StrConv(Left(c.Value, 1), vbUpperCase) = "P" Then
c.Value = Right(c.Value, Len(c.Value) - 1)
End If
Next
End Sub


"dex" wrote:

Yes i would rather use it in the macro. What is the syntax?




All times are GMT +1. The time now is 08:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com