Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
JackC
 
Posts: n/a
Default Find & Replace in VB macro

I have a macro that selects a range of cells and looks for the relative
column heading (i.e. !E or !G) and should replace it with the next sequential
column header. Unfortunately, I can not get the IF statement to proceed to
the next level once it does not find "!E" in the current selection.

The first macro defines the selection of cells and then calls the afore
mentioned Find & Replace macro.

Here is my current code.

If Selection.Find(What:="!E", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False) Then
Selection.Replace What:="!E", Replacement:="!F", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ElseIf FocusFR = Selection.Find(What:="!F", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False) Then
Selection.Replace What:="!F", Replacement:="!G", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

I am not sure if the Find statement has to be in an equation or what. The
goal is that the macro will find the current header, change it to the next
one, and then go back to the previous macro and get the next selection
criteria.
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

If there is nothing to replace, then it won't matter. You can drop that .find
portion and just use .replace.



JackC wrote:

I have a macro that selects a range of cells and looks for the relative
column heading (i.e. !E or !G) and should replace it with the next sequential
column header. Unfortunately, I can not get the IF statement to proceed to
the next level once it does not find "!E" in the current selection.

The first macro defines the selection of cells and then calls the afore
mentioned Find & Replace macro.

Here is my current code.

If Selection.Find(What:="!E", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False) Then
Selection.Replace What:="!E", Replacement:="!F", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ElseIf FocusFR = Selection.Find(What:="!F", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False) Then
Selection.Replace What:="!F", Replacement:="!G", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

I am not sure if the Find statement has to be in an equation or what. The
goal is that the macro will find the current header, change it to the next
one, and then go back to the previous macro and get the next selection
criteria.


--

Dave Peterson
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
Find and replace - problem with automatically changing formatting jwa90010 Excel Discussion (Misc queries) 6 October 28th 08 08:07 PM
How do you find and replace a Wildcard character in Excel? Wildcard Excel Discussion (Misc queries) 8 August 18th 05 01:18 AM
find and replace path name in Excel cells containing hyperlink leoe Excel Discussion (Misc queries) 1 August 9th 05 08:57 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:35 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"