VBA to simulate clicking on a cell with LET function which has a HYPERLINK function within

Ludwig

Board Regular
Joined
Apr 7, 2003
Messages
93
Office Version
  1. 365
Platform
  1. Windows
I have a specific cell that I can click on manually that has a HYPERLINK with calculated value based on the data within the worksheet. To work out the correct cell to hyperlink to, I use the LET function to remove duplicated function calls within the cell formula. This works fine.

What I need now is to simulate within an existing VBA macro is clicking on that cell to achieve the same effect. Selecting the cell and then issuing
VBA Code:
ActiveWorkbook.FollowHyperlink ActiveCell.Hyperlinks(1).Address
fails as I expected because the first function encountered in the cell is LET (within which the last parameter is "hyperlink(...)"), nor is there a link defined on the cell - because the cell to be jumped to needs to be calculated first based on the data in the worksheet.

I also looked into SENDKEY as an option but cannot find how to 'sendkey' a click of the mouse.
VBA Code:
    Range("P4").Select                  ' select this cell which will allow me to go to first unfilled data cell
    Application.SendKeys "~", True      ' except ~ is an Enter not a mouse click on the cell

What is the VBA code I need to simulate the mouse press on the cell (P4 in this case)?

Thanks for the help.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi, it's nothing to do with the LET() function ,the hyperlink() function is not an actual hyperlink that can be accessed by the hyperlinks property in VBA.

You would need to calculate the address you want to follow using the same method that you use in the formula.
 
Upvote 0
So can SENDKEY be used to generate my mouse click on the cell?
 
Upvote 0
No, not as far as I'm aware, is there a reason why you couldn't derive the address using the same logic you have used in HYPERLINK() function?

It might help generate some other ideas if you posted the LET(....,HYPERLINK()) function you are using.
 
Last edited:
Upvote 0
Here's the LET(..HYPERLINK(... ) ) formula I use in cell P4:
Excel Formula:
=LET( FirstMissingDataRowLCL, MIN( INDEX( FILTER( tbkWhRdgs[Row Nbr], tbkWhRdgs[Date of reading] = "", MAX( tbkWhRdgs[Row Nbr] ) + 1 ), 1 ),
               INDEX( FILTER( tbkWhRdgs[Row Nbr], tbkWhRdgs[kWh reading] = "", MAX( tbkWhRdgs[Row Nbr] ) + 1 ), 1 ),
               INDEX( FILTER( tbkWhRdgs[Row Nbr], tbkWhRdgs[Odometer reading] = "", MAX( tbkWhRdgs[Row Nbr] ) + 1 ), 1 ) ),
HYPERLINK( "#" & FirstMissingColm & FirstMissingDataRowLCL,
                                 "click here to go to first incomplete" & CHAR( 10 ) &
                                 IF( INDIRECT( ADDRESS( FirstMissingDataRowLCL, COLUMN( tbkWhRdgs[[#Headers],[Is Row Hidden]] ), 1, 1 ) ) = "H", "the HIDDEN ", "" ) &
                                 "data cell ...  i.e. " & FirstMissingColm & FirstMissingDataRowLCL )
)
Note - FirstMissingColm is a named cell with another formula in it. LET messes things up if I code it here [it forgets the "hyperlink" function and just provides the cell value as "#" & FirstMissingColm & FirstMissingDataRowLCL ignoring HYPERLINK's 2nd parameter rather than doing the expected HYPERLINK thing - I'm waiting for MS to fix that bug].

Back to *this* question: I have a circumvention for my question in place right now - in VBA I take the cell reference to go to from the text I've now included at the end of the resultant cell value. I would rather not have to do this but have VBA "mouse click" on P4 for me and jump as the cell HYPERLINK resolves to. Coding the equivalent formula into VBA means a second place to update in the future and I don't want to have to remember to do that if/when I make changes to the formula!
 
Last edited:
Upvote 0
Effectively what I'm doing is finding the first of 3 columns where data is missing. So first LET parameter finds the row across 3 columns, the second one determines the column for that row, then LET is supposed to allow me to run the HYPERLINK command to that cell.

Easy said like that, formula looks more complicated but achieves what I need ;)
 
Upvote 0

Forum statistics

Threads
1,223,152
Messages
6,170,389
Members
452,324
Latest member
stuart1980

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