Home » excel » excel – Sum of a column in Access VBA

excel – Sum of a column in Access VBA

Posted by: admin May 14, 2020 Leave a comment


Im trying to make an Excel file from an Access query. I need to calculate the amount for each column in the resulting table and add them to the last row as SUM. I transferd a table from queries to Excel sheet, but I can not add the amount. Is it possible to use the VBA inside Access to find the height of a column and add the sum of the column to the next cell?

How to&Answers:

If you do not want to do any job with functions in excel you could simply do it in the sql query in access and choose to export the query result. Here is an example:

enter image description here

SELECT Table1.[ID], Table1.[Field1], Table1.[Field2]
FROM Table1
union all
SELECT 'sum', sum(Table1.[Field1]), sum(Table1.[Field2])
FROM Table1;

enter image description here