I put in my 5 hours trying to figure this out, and now it's time to ask for help.
I am creating an "Inventory calendar" where each day we produce and sell a number of items. I want to see how many day's worth of an item I have on a particular day. The number of items we sell each day is different. Everything works until the If LastRowQ.Offset(-1,0).Value line where I get an "Object required" error. I want to divide the number of items that are left the second to last cell (the last cell is offset(-1,0) because the last cell results in a negative if it is not a 0) by the number of items sold that day (column H) so I get a decimal of how much of that day will be covered by the inventory we already have. Also, how do I get that value (remainder) to be put in cell R3?
Thanks!
Sub test()
Dim r As Integer, a As Integer, remainder As Single
remainder = 0
Range("B2").Select ' Today's inventory
Application.CutCopyMode = False
Selection.Copy
Range("Q2").Select ' Helper column to paste the remaining inventory for each day
ActiveSheet.Paste
For r = 2 To 10
While Cells(r, "Q").Value > 0
Cells(r + 1, "Q") = Cells(r, "Q").Value - Cells(r, 8).Value
r = r + 1
Wend
Next r
With ActiveSheet
LastRowQ = .Range("Q" & .Rows.Count).End(xlUp).Row
End With
If LastRowQ.Offset(-1, 0).Value > 0 Then
remainder = LastRowQ.Offset(-1, 0).Value / LastRowQ.Offset(0, -9).Value
' How do I put the value of "remainder" into cell R3?
End If
End Sub