VBA in current sheet only?

samilynn

Board Regular
Joined
Jun 24, 2003
Messages
166
Office Version
  1. 2016
Platform
  1. Windows
Hi, any suggestions on how I can change this code to only work in the Active Sheet?
It currently makes the changes in all the sheets in the Workbook.
Thanks,
Samantha


Option Explicit

Sub ReplaceNames()
Dim sht As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each sht In Worksheets
sht.Cells.Replace What:="ABC1", replacement:="AAAAAAAAAA", Lookat:=xlPart, MatchCase:=False
sht.Cells.Replace What:="XYZ1", replacement:="XXXXXXXXX", Lookat:=xlPart, MatchCase:=False
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:
VBA Code:
Sub ReplaceNames()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

ActiveSheet.Cells.Replace What:="ABC1", replacement:="AAAAAAAAAA", Lookat:=xlPart, MatchCase:=False
ActiveSheet.Cells.Replace What:="XYZ1", replacement:="XXXXXXXXX", Lookat:=xlPart, MatchCase:=False

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,145
Messages
6,123,289
Members
449,094
Latest member
GoToLeep

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