Highlight Row & Cell

Andy987

New Member
Joined
Feb 3, 2020
Messages
2
Office Version
  1. 2013
Hello all!

Looking for some help with a VBA. I want to highlight both row and columns of the selected cell and the below code is working however I was wondering if it is possible to control when the VBA is running. IE by putting "OFF" in cell A1 then the VBA would not run.

Thanks



Sub Worksheet_SelectionChange(ByVal Target As Range)

Application.ScreenUpdating = False
Application.FindFormat.Clear
Application.ReplaceFormat.Clear
Application.FindFormat.Interior.Color = RGB(236, 236, 236)
Application.ReplaceFormat.Interior.Color = xlNone
Cells.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
Application.FindFormat.Clear
Application.ReplaceFormat.Clear
Application.FindFormat.Interior.Color = xlNone
Application.ReplaceFormat.Interior.Color = RGB(236, 236, 236)
Target.EntireRow.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
Target.EntireColumn.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
Application.FindFormat.Clear
Application.ReplaceFormat.Clear
Application.ScreenUpdating = True


End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try adding
VBA Code:
If Lcase(Range("A1").Value)="off" Then Exit Sub
as the first line of code.
 
Upvote 0

Forum statistics

Threads
1,216,455
Messages
6,130,732
Members
449,589
Latest member
accountant606

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