

I've edited your code below to hopefully something that works. Range("$A$2:$DM$8442), use named ranges instead. Try to avoid cell referencing when writing VBA e.g.

Once you've set a variable, then at the end of your routine you should set it = nothing to clear it from memory. Once you've SET your LastCell you can use it as a reference in your code I've made LastCellColRef as a variable as this makes it clear that it is column 2 that is being searched in to find the last entry

This is a very important concept to learn about when writing VBA. The Dim part is setting the variables to use in your code. The main reason is to prevent your code breaking if the sheet is renamed. The first change I would make to this code is to replace the Sheets("UNNEEDED") part with the underlying sheet number e.g Sheet2.cells or Sheet3.cells You can see that sheet number next to the name in the VBA editor window. Set LastCell = Sheets("UNNEEDED").Cells(Rows.Count, LastCellColRef).End(xlUp).Offset(1, 0) LastCellColRef = 2 'column number to look in when finding last cell

Suppose an Excel Macro called “Macro1″ is saved in workbook ”RunExcelMacro”, which is a Macro to format worksheet. There are two ways to run Excel Macro from Access:ġ) Write a Macro in Excel first, and then call the Excel Macro from AccessĢ) Write Excel Macro in Access to run in Excel Run an existing Excel Macro from Access Of course you can export your Access data to a pre-formatted Excel template, but not all formatting can be pre-formatted and your exported data columns are not always continuous. However, it would be convenient if you can export the file out from Access to an Excel template containing Macro, and then tell Excel to run a Macro to format itself. By default, exporting Access report as Excel gives you no formatting but plain text. One of the uses to run Excel Macro from Access is when you use VBA to export tons of Access reports to Excel. Run Access Macro using RunCode Run Excel Macro from Access VBA
EXCEL VBA ON STARTUP SELECT SHEEN HOW TO
This Access tutorial explains how to run Excel Macro from Access VBA, either write Excel Macro directly in Excel or you can write Excel Macro in Access.
