Quantcast
Channel: Microsoft forum - dslreports.com
Viewing all articles
Browse latest Browse all 8524

[Excel] Change a Working Macro to Include two Different Cells?

$
0
0
I've got a macro that I use to add up the totals of all my invoices in a folder. It's been working well, at least until I updated the design of my invoice sheet, adding a few extra rows. The initial design had the total sum at cell F41. Later sheet designs have sum at F43. The present macro ignores all the sheets that have the total at F43 because there is nothing in F41 on those sheets. The result is about 3 dozen invoices didn't get counted. I found this error tonight while checking invoices against 1099 forms. I thought it would be simple enough to change the range from the current "F41" and update it to "F41:F43", however, that causes a 'type mismatch' error when the macro is run. Is there a simple way to get this macro to find totals in either F41 OR F43 on any of the invoices it finds in the working directory? Maybe my syntax is wrong? Or maybe I need fifty new lines of code to add this one simple feature? Any ideas for an easy to implement rewrite would be appreciated. Sub ADD_INVOICE_TOTALS() Dim MyFolder As String Dim MyFile As String Dim MyValue As Double '-------------------- MyValue = 0 MyFolder = "D:\Excel Invoices\Amplifier Experts Invoices\2014\" MyFile = Dir(MyFolder & "*.XLS") Do While MyFile "" Application.StatusBar = MyFile Workbooks.Open Filename:=MyFolder & MyFile MyValue = MyValue + ActiveWorkbook.Sheets(1).Range("F41").Value ThisWorkbook.Sheets(1).Range("B2").Value = MyValue ActiveWorkbook.Close savechanges:=False MyFile = Dir Loop Application.StatusBar = FalseEnd Sub

Viewing all articles
Browse latest Browse all 8524

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>