Please help me!

ryan0521

Board Regular
Joined
Dec 7, 2016
Messages
79
Hello everyone,

Can someone fix my Macro, I have a workbook with only 1 sheet, this macro button will update their values if someone copy and paste another worksheet in my workbook.

However, if the sheets were not yet completed and already click the macro button, it keeps updating values again and an error appears that the macro wouldn't continue. Please fix my codes below.

Code:
Sub Recalculate_Click()


ActiveSheet.Unprotect Password:="FPRC"
Dim sht As Worksheet
Dim fnd As Variant
Dim rplc As Variant


fnd = "="
rplc = "="


For Each sht In ActiveWorkbook.Worksheets
  sht.Cells.Replace what:=fnd, Replacement:=rplc, _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
    SearchFormat:=False, ReplaceFormat:=False
    
Next sht


ActiveSheet.Protect Password:="FPRC"


End Sub
 
Last edited by a moderator:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this:
Modify the find and replace values. They cannot be the same.

Code:
Sub Recalculate_Click()
Dim sht As Worksheet
Dim fnd As Variant
Dim rplc As Variant
ActiveSheet.Unprotect Password:="FPRC"
Dim c As Range
fnd = "[COLOR=#ff0000]Me[/COLOR]"  'Modify find to your needs
rplc = "[COLOR=#ff0000]You[/COLOR]" 'Modify replace to your needs
    For Each sht In ActiveWorkbook.Worksheets
        
        For Each c In sht.UsedRange
            c.Replace what:=fnd, Replacement:=rplc, _
            LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
            SearchFormat:=False, ReplaceFormat:=False
        Next
    
    Next
    ActiveSheet.Protect Password:="FPRC"

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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