I have two hyperlinks in my excel document.
On Sheet1, in cell A1 I have written the formula, =HYPERLINK("#'Sheet1'!A1","click")
.
On Sheet1, in cell A2 I have done what I think is the same but using a interactive GUI. Right click in cell A2 => Hyperlink => Place in this document => (Type the cell reference) A2.
I also have written a very short sub so that when I click on these hyperlinks I get a message box.
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox ActiveCell
End Sub
I have placed this macro in Sheet1.
When I click on cell A2 I get a MsgBox with the cell value in. As expected
However, when I click on cell A1 nothing happens.
Why are these two links behaving differently? How can I make cell A1 behave in the same way as cell A2 whilst still using a formula in the cell?
So Why?
I have a program that generates a CSV file. For simplicity the structure looks a little like this.
f1,f2,compare
f3,f2,compare
This means it is easy to overwrite the format.
I then open this file and save it as a .xlsm
. What I wanted to have is when the compare is clicked it would run a macro. This could be in the form of a button or a hyperlink or anything else as long as it is obviously clickable.
Hence why I was going for the approach of =HYPERLINK("#'Sheet1'!A1","click")
as it was easy to increment the number after the column and still show it was something that was clearly clickable.
Therefore it would be a quick change to get the CSV file output in a format of
f1,f2,"=HYPERLINK(""#'Sheet1'!C1"",""compare"")"
f3,f2,"=HYPERLINK(""#'Sheet1'!C2"",""compare"")"
The goal of this is to have something that is as automated as possible as this workbook could have over a thousand row so it is not feasible for me to manually sort out a compare button on each row
Update 2
When the compare button is clicked, a macro is run. This macro is called CompareFiles
. It takes the values from the cells on the same row but in columns a and b, passes them into a shell command, and opens a different program that is used to compare the files.