Run VBA in selected cells only?

samilynn

Board Regular
Joined
Jun 24, 2003
Messages
185
Office Version
  1. 2016
Platform
  1. Windows
I use this code to change assigned codes to employees actual names. However, it runs on the entire sheet. How do I change it to run only on the range that I am selecting before running the macro?
Thank you!
Samantha

Option Explicit

Sub Names()
Dim sht As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Cells.Replace What:="ABC1", Replacement:="NAME1", LookAt:=xlPart, MatchCase:=False
ActiveSheet.Cells.Replace What:="XYZ", Replacement:="NAME2", LookAt:=xlPart, MatchCase:=False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Change this:
VBA Code:
ActiveSheet.Cells.Replace...
to this:
VBA Code:
Selection.Replace...
 
Upvote 0
Solution
Change this:
VBA Code:
ActiveSheet.Cells.Replace...
to this:
VBA Code:
Selection.Replace...
Thank you Joe! Duh...that was so simple. Thank you for taking the time :)
 
Upvote 0

Forum statistics

Threads
1,226,079
Messages
6,188,773
Members
453,499
Latest member
samdan87153

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