Creating a button for a VBA Macro to turn it on and off (crosshatchings) also specifying a range for VBA crosshatchings

elmar007

Board Regular
Joined
Nov 9, 2012
Messages
86
Hi all

I already have a VBA code which allows me to have crosshatchings which helps to prevent me inputting errors.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.ScreenUpdating = False
' Clear the color of all the cells
Cells.Interior.ColorIndex = 0
With Target
' Highlight the entire row and column that contain the active cell
.EntireRow.Interior.ColorIndex = 5
.EntireColumn.Interior.ColorIndex = 3
End With
Application.ScreenUpdating = True
End Sub


a) However I want to create 1 button to sit on the worksheet (not on the ribbon) that allows users to turn the hatching on and off as necessary ie. press for on/off

I have not created buttons before (all I know is that there are 2 methods in which they can be created 'Form Control' and 'ActiveX' > I dont understand the difference between them!)

As I am new at this bit please may I have stepbystep?

b) additionally can I modify my VBA code to suggest a range for the crosshatching rather than them being over the whole worksheet ie A7:AY39

cheers
RM
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

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