Change a WorksheetSelectionChange to run once

SendHalp3

New Member
Joined
Oct 2, 2021
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Hi! I have the following code on a sheet, this is a heavy workbook and I'm worried if its continuously running with every click it will slow down the user. How can I modify this to run only on the first click on the ActiveWorksheet, or so i can assign it to a button to be only run when clicked.

Any help would greatly be appreciated! Thank you :)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range
For Each cell In ActiveWorkbook.ActiveSheet.Rows("3").Cells
If cell.Value = "Hide" Then
cell.EntireColumn.Hidden = True
Else
If cell.Value = "Show" Then
cell.EntireColumn.Hidden = False
End If
End If
Next cell
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about
VBA Code:
Sub SendHalp()
   Dim Cl As Range
   
   For Each Cl In Range("A3", Cells(3, Columns.Count).End(xlToLeft))
      Cl.EntireColumn.Hidden = Cl.Value = "Hide"
   Next Cl
End Sub
and you can assign this to a form control button, or shape.
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,843
Members
449,193
Latest member
MikeVol

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