Thread: help with loop
View Single Post
  #3 (permalink)  
Old August 4th, 2012, 12:41 PM
shinpaj shinpaj is offline
Registered User
 
Join Date: Aug 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello. I don't see that you posted you question in another section, perhaps you got your answer, but you don't need the .value bit following user input in your code - that is the reason for the error. However, an unexpected result occurs because the value entered is overwritten each time the user enters the weight.

Reason: the code Cells(emptyRow, 5).Value = Weight references the variable emptyRow, the empty row in column A never changes because the user needs to go through 4 iterations, causing the input to be overwritten each input...and that is not what you want. The following fixes that (with offset(i,0)). You still have undfined TieWeight, the sub exits, so it is commented out.

Hope this helps:

Sub GetWeight()

'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

i = 0

For i = 1 To 4
Weight = InputBox("Enter Weight of cavity #" & i)
Cells(emptyRow, 5).Offset(i, 0).Value = Weight
'If TieWeight = "" Then Exit Sub
Next i

End Sub

Regards
Sean

Last edited by shinpaj; August 4th, 2012 at 12:44 PM..