tags:

views:

57

answers:

0

hi I am populating the data from MS Access to Excel through VBA. The data are populated in the Range (A to I ).I wants to insert the Formula in each excel cell during the population time. i trying this code

varConnection = "ODBC; DSN=MS Access Database;DBQ=D:\sample\table.accdb; Driver={Driver do Microsoft Access (*.accdb)}"

   varSQL = "SELECT * FROM LeftPanes"
   With ActiveSheet.QueryTables.Add(Connection:=varConnection, Destination:=ActiveSheet.Range("B4"))
           .CommandText = varSQL
           .Name = "Query-39008"
           .Refresh BackgroundQuery:=False
            With .ResultRange
            .Columns(.Columns.Count).Offset(1).Resize(.Rows.Count - 1).Formula = "=(RC[-2]*RC[-1])/1000"
            End With

End With its working properly but a issue is this code only add the formula at the last cell only there is no option to Specify the cell range there is any possibility to insert the formula in the Middle cell.Thanks in advance