Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default find replace macro

I have a macro that finds and replaces (I found it here, thanks!) I need to
adapt it from looping through all worksheets to just cells I select. Can
someone help?


TIA


Todd




Sub FindReplace()


Dim wks As Worksheet
Dim WhatToReplace As String
Dim WithWhat As String


WhatToReplace = InputBox(Prompt:="What this time?")
If WhatToReplace = "" Then
Exit Sub
End If



WithWhat = InputBox(Prompt:="what should: " & Chr(34) & _
WhatToReplace & Chr(34) & " be replaced with?")
If WithWhat = "" Then
Exit Sub
End If

For Each wks In ActiveWorkbook.Worksheets
wks.Cells.Replace what:=WhatToReplace, _
Replacement:=WithWhat, lookat:=xlPart, _
MatchCase:=False
Next wks


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default find replace macro

Todd,

Replace

wks.Cells.Replace ...

with either an address, like

wks.Range("A1:B10").Replace ....

or to act on the current selection from each sheet

wks.Select
Selection.Replace ....

HTH,
Bernie
MS Excel MVP

"Todd L." wrote in message
...
I have a macro that finds and replaces (I found it here, thanks!) I need

to
adapt it from looping through all worksheets to just cells I select. Can
someone help?


TIA


Todd




Sub FindReplace()


Dim wks As Worksheet
Dim WhatToReplace As String
Dim WithWhat As String


WhatToReplace = InputBox(Prompt:="What this time?")
If WhatToReplace = "" Then
Exit Sub
End If



WithWhat = InputBox(Prompt:="what should: " & Chr(34) & _
WhatToReplace & Chr(34) & " be replaced with?")
If WithWhat = "" Then
Exit Sub
End If

For Each wks In ActiveWorkbook.Worksheets
wks.Cells.Replace what:=WhatToReplace, _
Replacement:=WithWhat, lookat:=xlPart, _
MatchCase:=False
Next wks


End Sub



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
Macro to Find and Replace R Storey Excel Discussion (Misc queries) 6 December 6th 06 07:04 PM
find&replace macro Elainey Excel Worksheet Functions 0 January 6th 06 09:20 PM
Find/replace macro VB Newbie Excel Programming 1 November 13th 04 01:48 AM
A Macro to Do Find and Replace Eric Excel Programming 2 February 27th 04 12:22 AM
Using Find & Replace in macro Bob C[_3_] Excel Programming 11 October 30th 03 07:02 PM


All times are GMT +1. The time now is 11:15 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"