Where I work we perform a monthly inventory count and I must create a report for the production managers. In this report I have multiple columns to sum and after 5 years of doing this manually, it has gotten old. There has to be a way to search out these cells with code and perform this task automatically, but I'm not sure how to do it. While watching a video on VBA, I found the following code promising and can find the first empty cell when running it, but not sure what to do to insert the function and if I did, I'm not sure how to search out for the next cell to enter the function.
Sub FindFirstEmptyCell_DoLoop()
Worksheets("Compare").Activate
Range("F5").Activate
Do
If ActiveCell.Value = "" Then Exit Do
ActiveCell.Offset(1, 0).Activate
Loop
End Sub
By recording a macro, I can see the code to add the sum, but still lost as what needs to be done.
Range("F15").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
Range("F27").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
Range("I71").Select
I have attached a spreadsheet with sample data with highlighted cells that need a sum of the cells above it.
I cannot upload a spreadsheet or image from my work computer so hopefully the explanation will be good enough. If not, I will upload it from home later tonight.
BTW... if the cells that are required to be SUMMED were always the same, I could just use a recorded macro to do the job. However, because inventory items and added and deleted throughout any given month, these locations are not always the same.
Brian
Bookmarks