Thread: Error 1004 help
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson[_4_] Greg Wilson[_4_] is offline
external usenet poster
 
Posts: 218
Default Error 1004 help

Your code returns this error because it tries to reference
a cell beyond the last column in the worksheet. If I
understand what you're trying to do, I think you just need
to rezero the Y variable after each inner loop as follows:

Private Sub UpdateOnhand()
Dim X As Integer
Dim Y As Integer
X = 0
Y = 0
Do
Do
Range("ONHAND").Offset(X, Y).Value = _
Range("ONHAND").Offset(X, Y).Value + _
Range("Received").Offset(X, Y).Value
Y = Y + 1
Loop Until Y = 119
Y = 0
X = X + 1
Loop Until X = 7
End Sub

Regards,
Greg