Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Excel, can I use a hyperlink to run vba macro?

Tags:

excel

vba

I have a spreadsheet that has many rows of data. I would like to be able to click on a cell that will run a macro using the data from that row. Since the number of rows will always be changing, I though a hyperlink for each row might be the best way.

   ROW MeterID   Lat    Long   ReadX  ReadY  ReadZ   CoeffA  CoeffB  CoeffC
   2   10f62gs   34.1   33.3   102.2  231.3  382.2   4.34    22.1    0.002
   3   83gs72g   34.4   31.4   109.2  213.1  372.1   2.23    12.7    0.023
   4   43gS128   33.3   32.2   118.8  138.7  241.8   1.94    5.08    0.107

Is there a way to run a vba macro from clicking on a hyperlink and being able to know the row of the cell that clicked on the hyperlink?

like image 562
Jason Avatar asked Feb 25 '15 20:02

Jason


People also ask

How do I hyperlink in Excel VBA?

Step 1: First, select the cell A1 of the worksheet example 1. Step 2: Now, open hyperlinks using the Active Cell object. Add method. Step 3: The first argument is “Anchor,” i.e., in which cell we would link to create the VBA hyperlink.

How do I run a macro from a website in Excel?

If I am correct in assuming that you're asking if a vba macro can be run automatically after opening it from a link on a webpage rendered by a browser, the best way to do that is to set code to run automatically whenever the workbook linked in the webpage is opened.


1 Answers

This will work for you

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
        MsgBox "Row " & ActiveCell.Row & " is clicked"
End Sub
like image 86
Jeanno Avatar answered Sep 28 '22 08:09

Jeanno