LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 16
Default Macro to Find & Replace

In Excel 2002+ when you hit [CTRL-F] to do a find, it allows you the
option of searching within the active sheet or the entire workbook.
Once you start a search and you specify, "Sheet" or "Workbook", that
information is stored for later searches, so when you hit [CTRL-F]
again, the search criteria will default to what you had specified
previously. This is an issue with my macros because they were designed
based on the assumption that a find could ONLY search the active sheet.

Example:

Sheets("Sheet10").Select
Sheets("Sheet10").Range("B7:F10").Select
Selection.Replace What:="25", Replacement:="40", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Problem:

If someone is running this macro from their computer who has previously
set the Find & Replace to search within the "Workbook", this part of
the macro above will replace any instances of "25" and replaces it with
"40" within the ENTIRE workbook, when I need it somehow specified to
replace in ONLY the active sheet.

In other words, I want to be able to set the search criteria to "Sheet"
or "Workbook" through Excel VB to control where it looks. Even though
I tried specifying ActiveSheet.Replace it STILL replaces through the
entire workbook.

Is there perhaps a "Within:=" tag? Could I do something like the
following:

Selection.Replace What:="25", Replacement:="40", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, Within:=Sheet

 
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: Find and replace Bertie Excel Discussion (Misc queries) 1 May 29th 06 02:01 PM
Help! - Lost function in Find & Replace! jmn13 Excel Discussion (Misc queries) 1 May 25th 06 06:16 PM
Find and Replace koba Excel Discussion (Misc queries) 1 November 23rd 05 10:19 PM
Find and replace of word causes change of font formatting jwa90010 New Users to Excel 4 July 22nd 05 08:10 PM
find and replace steve Excel Discussion (Misc queries) 1 June 23rd 05 01:43 AM


All times are GMT +1. The time now is 02:55 PM.

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

About Us

"It's about Microsoft Excel"