View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Delete part of cell value

Is it ok to get rid of all the SADMIN's?

Sometimes, it takes longer to loop through all the cells instead of just doing a
single Edit|Replace.

Record a macro when you do:
Select the column
Edit|Replace
What: SADMIN
with: (leave blank)
replace all

(The asterisk is a wild card that represents all the trailing characters.)

Then tweak the code to get rid of the selects:

with worksheets("Sheet2").range("m1").entirecolumn
.cells.replace What:="SADMIN", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End with

I'm not sure if matching case is important to you, though.

And you're also adding that trim() call. So your code is doing more than what
mine would do.

Sinner wrote:

Hi,

Below code removes word 'SADMIN' if found in each cell of column M of
sheet2.
----------------------------------------------------------------------
Sub RMV_SADMIN()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

For Each Cell In Range("sheet2!M:M")

sStr = Trim(Cell.Value)
If Left(sStr, 6) = "SADMIN" Then
Cell.Value = Trim(Right(sStr, Len(sStr) - 6))

End If

Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Worksheets("Sheet2").Activate
Range("A1").Select

End Sub
-----------------------------------------------------------------

Any further improvement is welcomed.


--

Dave Peterson