Find Replace with Macro

raj08536

Active Member
Joined
Aug 16, 2007
Messages
322
Office Version
  1. 365
Platform
  1. Windows
I want to only find replace in the selected cells.
Following code only find replace change the first cell of the selected cells.

Can you please help?


Sub FormulaTab36()

Dim CMonth As Variant
Dim FirstM As Variant


CMonth = Sheets("000.Current month").Cells(6, 2).Value
FirstM = Sheets("000.Current month").Cells(59, 2).Value



'MsgBox CMonth
'MsgBox FirstM
Sheets("36.Graphs").Select



Sheets("36.Graphs").Range(FirstM & "34:" & "M34").Select

Call ReplaceMultipleTabs36

Sheets("36.Graphs").Range(FirstM & "88:" & "M88").Select
Call ReplaceMultipleTabs36
Sheets("36.Graphs").Range(FirstM & "141:" & "M141").Select
Call ReplaceMultipleTabs36
Sheets("36.Graphs").Range(FirstM & "215:" & "M215").Select
Call ReplaceMultipleTabs36


End Sub


Sub ReplaceMultipleTabs36()
Dim c As Range
Dim Opt As Variant
Dim Fnd36 As Variant
Dim RplAce36 As Variant



Fnd36 = Sheets("000.Current month").Cells(61, 2).Value
RplAce36 = Sheets("000.Current month").Cells(62, 2).Value


ActiveCell.Replace What:=Fnd36, Replacement:=RplAce36, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _
False, ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Selection.Find(What:=Fnd36, After:=ActiveCell, LookIn:= _
xlFormulas2, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate



End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
This is an example of how you could do it. Put your different ranges in that Union and there you go

VBA Code:
Sub jec()
 Fnd36 = "Old"
 RplAce36 = "New"
 Set ar = Union(Range("A1:A4"), Range("E1:E2"), Range("C4:C8"))
 ar.Replace Fnd36, RplAce36
End Sub
 
Upvote 0
Solution
This is an example of how you could do it. Put your different ranges in that Union and there you go

VBA Code:
Sub jec()
 Fnd36 = "Old"
 RplAce36 = "New"
 Set ar = Union(Range("A1:A4"), Range("E1:E2"), Range("C4:C8"))
 ar.Replace Fnd36, RplAce36
End Sub
Really Appreciated...
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top