Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default replace all the cells in sheet that include spsific string-via mac

i need to replace all the cells in spesific sheet that include spesific
string with other.
i did the following code:(but since there are lot of cells in sheet , it is
very very havy. is there a better way? )

Workbooks(Activebook).Sheets("mySheet").Select
Cells.Select

mystr = "xxx"
For Each cell In Selection
If (InStr(cell.Value, mystr) = 1) Then
cell.Replace What:=mystr, Replacement:="", LookAt:=xlPart,
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False,
ReplaceFormat:=False

End If
Next cell


--
Miri Tz.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default replace all the cells in sheet that include spsific string-via mac

Miri,

You could limit your code to the used range instead of the entire worksheet.
Try this and note that I've added a space either side of your string. The
reason for this is if your string was 'add' it would remove the 'add' from
'Haddock'.

Sub stantial()
Sheets("Sheet1").UsedRange.Select
mystr = " xxxx "
For Each cell In Selection
If InStr(1, cell.Value, mystr, 1) 0 Then
cell.Replace What:=mystr, Replacement:=""
End If
Next cell
End Sub

Mike

"Miri" wrote:

i need to replace all the cells in spesific sheet that include spesific
string with other.
i did the following code:(but since there are lot of cells in sheet , it is
very very havy. is there a better way? )

Workbooks(Activebook).Sheets("mySheet").Select
Cells.Select

mystr = "xxx"
For Each cell In Selection
If (InStr(cell.Value, mystr) = 1) Then
cell.Replace What:=mystr, Replacement:="", LookAt:=xlPart,
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False,
ReplaceFormat:=False

End If
Next cell


--
Miri Tz.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Hyperlink Addresses Help 'Dim OldStr As String, NewStr As String Ron[_14_] Excel Programming 6 January 23rd 07 07:38 PM
How do you include a quotation as part of a string ?? Dan Thompson Excel Programming 2 November 4th 06 06:11 AM
How do I add cells to a balance sheet which will include new sum? Karen Excel Discussion (Misc queries) 3 September 13th 06 08:59 PM
How do I replace last numeric string from a alphanumeric string? Christy Excel Discussion (Misc queries) 3 August 11th 06 12:17 AM
How can I include a " in my string? Ai_Jun_Zhang Excel Programming 1 August 3rd 05 12:49 AM


All times are GMT +1. The time now is 04:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"