Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default Variable in a Search and Replace macro

I have a formula in many worksheets that needs to be modified.

I have a macro that goes to each worksheet but I would like to use a
variable in the text to be replaced so I dont have to update the macro for
each sheet.

I would like to something like;

FOR X= 1 TO 80

Selection.Replace What:="min1", Replacement:="min27", etc etc....


NEXT X

Where the replacement string becomes

Replacement:="minX"

and increments for each x

Is this possible?

thanks
sandy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Variable in a Search and Replace macro

Do you mean something like

Sub FindIt(myVar)
FOR X= 1 TO 80
Selection.Replace What:="min1", Replacement:=myVar, etc etc....
NEXT X
End Sub

which you would usitlise like so


FindIt "min27"
FindIt "minX"

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Sandy" wrote in message
...
I have a formula in many worksheets that needs to be modified.

I have a macro that goes to each worksheet but I would like to use a
variable in the text to be replaced so I dont have to update the macro for
each sheet.

I would like to something like;

FOR X= 1 TO 80

Selection.Replace What:="min1", Replacement:="min27", etc etc....


NEXT X

Where the replacement string becomes

Replacement:="minX"

and increments for each x

Is this possible?

thanks
sandy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Variable in a Search and Replace macro

Sandy,

Perhaps:

Replacement:="min" & X

Don't know what you want to use as the replace, though....

HTH,
Bernie
MS Excel MVP


"Sandy" wrote in message
...
I have a formula in many worksheets that needs to be modified.

I have a macro that goes to each worksheet but I would like to use a
variable in the text to be replaced so I dont have to update the macro for
each sheet.

I would like to something like;

FOR X= 1 TO 80

Selection.Replace What:="min1", Replacement:="min27", etc etc....


NEXT X

Where the replacement string becomes

Replacement:="minX"

and increments for each x

Is this possible?

thanks
sandy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default Variable in a Search and Replace macro


Hi Bob -

I only need to update part of the variable in the macro....

This is the folumla I need to update in Col D:
=IF(ISBLANK(G9)," ",IF(AND(B9<max53,B9=min53),"pass","Fail"))

This is the full macro:

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveSheet.Next.Select

ActiveSheet.Unprotect
Columns("D:D").Select

Selection.Replace What:="min1", Replacement:="min54",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="max1", Replacement:="max54", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("g9").Select


Each time I go to the next worksheet, I need to update the named cell that
is called up in the formula -- ie "min54" becomes "min55"
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Variable in a Search and Replace macro

Perhaps

i=53
For Each sh In Activeworkbooks.Worksheets
With sh
.Unprotect
.Columns("D:D").Select.Replace What:="min1", _

Replacement:="min" & i,
LookAt:=xlPart,
_

SearchOrder:=xlByRows, _

MatchCase:=False, _

SearchFormat:=False, _

ReplaceFormat:=False
.Columns("D:D").Select.Replace What:="min1", _

Replacement:="max" & i,
LookAt:=xlPart,
_

SearchOrder:=xlByRows, _

MatchCase:=False, _

SearchFormat:=False, _

ReplaceFormat:=False
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
.EnableSelection = xlUnlockedCells
i = i +1
Next sh


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Sandy" wrote in message
...

Hi Bob -

I only need to update part of the variable in the macro....

This is the folumla I need to update in Col D:
=IF(ISBLANK(G9)," ",IF(AND(B9<max53,B9=min53),"pass","Fail"))

This is the full macro:

ActiveSheet.Protect DrawingObjects:=True, Contents:=True,

Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveSheet.Next.Select

ActiveSheet.Unprotect
Columns("D:D").Select

Selection.Replace What:="min1", Replacement:="min54",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="max1", Replacement:="max54", LookAt:=xlPart,

_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("g9").Select


Each time I go to the next worksheet, I need to update the named cell that
is called up in the formula -- ie "min54" becomes "min55"



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 Search and Replace [email protected] Excel Discussion (Misc queries) 2 September 23rd 08 01:13 PM
macro to search and replace with offset Tim Excel Discussion (Misc queries) 5 December 11th 04 09:30 PM
Macro to Search and Replace Excel_Rookie[_3_] Excel Programming 1 September 23rd 04 05:09 PM
SEARCH & REPLACE MACRO Josh[_11_] Excel Programming 2 August 4th 04 05:07 PM
Macro search replace question WDP[_2_] Excel Programming 1 August 28th 03 06:18 AM


All times are GMT +1. The time now is 01:01 AM.

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"