Insert and Run a Query Formula

To create a macro that inserts and runs a Query formula to a target cell, add this method in to your macro along with the Query:

Sub InsertAndExecuteQueryFormulaToCell ()
QAAMacro.InsertAndExecuteQueryFormulaToCell
"H13","=QAA_SR(""1,2,ss5,LA,F='PK1,K=DbC,F=A,K=/LA/Ldg,F=10000,T=13000,
K=/LA/AccCde,F=2005/009,T=2005/009,K=/LA/Prd,E=0,O=/LA/Ldg,E=0,O=/LA/AccCde,
E=0,O=/LA/Prd,RT=4154,RF=111111011,AF=1,TP=,"",)"
End Sub

To insert the query to sheets other than the active sheet, change the cell reference from H13 to SheetName!H13.

This macro supports all query formulas:

  • QAA_RL: Reference Link
  • QAA_SL: Summary Link
  • QAA_SR: Summary Report
  • QAA_DR: Detail Report