Object Variable or With Block Variable Not Set

Chandresh

Board Regular
Joined
Jul 21, 2009
Messages
146
Hi Team , getting error while finding and replacing macro. if the macro doesn't find some data it stops and shows the below error. could you please help me

Capture.JPG


Below is the code
VBA Code:
Sub Findandreplace()
'
' MacroAbc
'

'
    Sheets("PeriodwiseA").Select
    Columns("B:B").Select
    Range("B48").Activate

    Selection.Find(What:="   (Face Value -5)", After:=ActiveCell, LookIn:= _
        xlFormulas2, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate

    Selection.replace What:="   (Face Value -5)", Replacement:="", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2

    Selection.replace What:="   (Face Value -1)", Replacement:="", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2

    Selection.replace What:="   (Face Value -10)", Replacement:="", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
   
Selection.replace What:="   (Face Value -2)", Replacement:="", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
       
    Selection.replace What:=" (POST DEMERGER)", Replacement:="", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
       
    Selection.replace What:=" (DEMERGED COMPANY)", Replacement:="", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
       
End Sub

Thanks in advance
 
Last edited by a moderator:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You will get that error if the Find operation fails. I can't see any point to having it in your code so you may as well just remove it.
 
Upvote 0
You will get that error if the Find operation fails. I can't see any point to having it in your code so you may as well just remove it.
HI i am replacing value like - (Face Value -5), (Face Value -5), (Face Value -10), (POST DEMERGER) & (DEMERGED COMPANY) with blank , please help
 
Upvote 0
I can see that, but the Find part doesn't actually alter the outcome, so it is unnecessary and you can just remove it.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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