Run macro only in certain range double clicked

johnohio

New Member
Joined
May 12, 2005
Messages
48
Office Version
  1. 2016
Platform
  1. Windows
I have a spreadsheet where the sheet that is locked and if the user double clicks in a certain column I would like a macro to run.

for example..
there are 100 rows, hers are 3 of them...

1709214639567.png


if the user double clicks on on the first column a macro will run, double click on any other cell nothing happens.
The spreadsheet needs to be locked so the user cannot edit.


Thanks everyone
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Like this?
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If Not Target.Column = 1 Then
   Cancel = True
   Exit Sub
End If

msgbox "Column 1 was double clicked"
Cancel = True 'may need this to suppress message re: changing protected sheet

End Sub
 
Upvote 0
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Not Target.Column = 1 Then Cancel = True Exit Sub End If msgbox "Column 1 was double clicked" Cancel = True 'may need this to suppress message re: changing protected sheet End Sub
That does not work because the worksheet is locked.
 
Upvote 0
I protected the sheet but allowed user to select locked and unlocked cells. Perhaps you didn't have those settings? I'm rusty, but I thought that setting allowed users to do that but still not make changes.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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