Macro to run on clicking "A2"

im_kaushal

New Member
Joined
May 8, 2010
Messages
27
Hi All,

How can I make my macro to run everytime I Double-Click on the cell "A2".
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
In the WorkSheet module (RightClick the sheet tab and choose "View Code")
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If Target.Address <> "$A$2" Then Exit Sub
'your code
End Sub

lenze
 
Upvote 0
Just out of the curiosity one more question arises in my mind. What if my target range is "A2:A10" and I want my macro to run everytime I double click any of the cell in the above mentioned range.

Thanks,
Kaushal
 
Upvote 0
Try

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A2:A10")) Is Nothing Then Exit Sub
Cancel = True
'your code
End Sub
 
Upvote 0
Read this thread with interest and wondered if a variation to above code could be used whereby a double click on any cell in range A1:O100 would activate the macro to hide columns F:K.

My present macro is
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
If Target.Cells.Count = 1 And Target.Address = "$A$2" Then
  If Target = "" Then
    Columns("f:T").EntireColumn.Hidden = False
  ElseIf LCase(Target.Value) = "h" Then
    Columns("F:k").EntireColumn.Hidden = True
  ElseIf LCase(Target.Value) = "2q" Then
    Columns("B:G").EntireColumn.Hidden = True
  End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
And columns are hidden when I insert "h" in A2.

Pedro
 
Upvote 0
Try

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A1:O100")) Is Nothing Then Exit Sub
Cancel = True
Columns("F:K").Hidden = True
End Sub
 
Upvote 0
Perhaps this: double click to hide, right click to unhide

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A1:O100")) Is Nothing Then Exit Sub
Cancel = True
Columns("F:K").Hidden = True
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A1:O100")) Is Nothing Then Exit Sub
Cancel = True
Columns("F:K").Hidden = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,040
Messages
6,128,454
Members
449,455
Latest member
jesski

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