Adam
Adam

Reputation: 83

Execute Macro after data refresh

The macro below updates Column A with a hyperlink function.

How do I run this after a data refresh on my query/datasource is clicked?

I tried writing a change condition on my worksheet.

Sub InsertHyperlinkFormulaInCell()

currentRow = 2   
While Cells(currentRow, 2) <> "" 'check whether Column B is empty, stop if it is
ActiveWorkbook.Worksheets("Query").Cells(currentRow, 1) = "=HYPERLINK(CONCAT(X" & currentRow & ",B" & 
currentRow & "),W" & currentRow & ")"
currentRow = currentRow + 1
Wend

End Sub

Upvotes: 0

Views: 748

Answers (1)

Gitty
Gitty

Reputation: 166

Instead of manually refreshing your query, do it from the macro and then continue with your code.

Sub InsertHyperlinkFormulaInCell()

Query.QueryTable.Refresh

'rest of your code here

End Sub

Upvotes: 2

Related Questions