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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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