Macro to double click cell A2 on Active Sheet once Drop down in A1 has been selected from Data Validation List

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
Once a user has selected an item from the drop down in Cell A1 on the active sheet ("Adjustments:) using Data Validation , the user double clicks on A2 , which has a hyperlink formula, and it will then go to the appropriate cell

I tried to write code to do this, but it only goes to A2 and does not go to the appropriate cell for Eg A55

Kindly amend my code

Code:
 Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then 'Change "$A$1" to the cell address of your drop down list
        On Error Resume Next
        Dim hyperlink As hyperlink
        Set hyperlink = Range("A2").Hyperlinks(1) 
        On Error GoTo 0
        If Not hyperlink Is Nothing Then
            hyperlink.Follow
        End If
    End If
End Sub
 
Many Thanks Jafaar, but certain of your code appears in red in the worksheet module


Code:
 Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As LongPtr)
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Many Thanks Jafaar, but certain of your code appears in red in the worksheet module


Code:
 Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As LongPtr)
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
You can ignore the code in red and leave it as is. It is for conditional compilation. It won't affect anything.

Edit:
BTW, did the code I posted actually work for clicking the hyperlink in cell A2 ?
 
Upvote 0
Thanks for the explantion and your help. Unfortunately, I could not get the code to work. JimmyPop's solution worked for me
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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