Wrox Programmer Forums
|
Forum and Wrox.com Feedback Post your suggestions for improving the Forums or Wrox.com or questions for the staff here. "Where can I find the code for my book?"
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Forum and Wrox.com Feedback section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 3rd, 2012, 09:25 PM
Authorized User
 
Join Date: Jan 2012
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default help with loop

Wanting the input box repeat four times, that part of code works. However, I want the new values to be entered on the next empty row of worksheet of column 5 or ("E").
Ex:
Enter Weight of cavity #1
Answer: 325
Enter Weight of cavity #2
Answer: 328
Enter Weight of cavity #3
Answer: 563
Enter Weight of cavity #4
Answer: 569

Each answer should advance down in column 5.

Code:
Sub GetWeight()
    i = 0
    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
    For i = 1 To 4
        Weight = InputBox("Enter Weight of cavity #" & i)
        Cells(emptyRow, 5).Value = Weight.Value (Runtime error 424 occurs here) 
        If TieWeight = "" Then Exit Sub
    Next i
End Sub
Hope that make sense. Thanks to all for help.

Last edited by pooky; August 3rd, 2012 at 09:28 PM..
  #2 (permalink)  
Old August 4th, 2012, 05:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You posted this in a general forum feedback category. To attract relevant viewers, consider posting this in one of the categories that matches your technology. Currently, it's hard to tell what this is about.

Cheers.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old August 4th, 2012, 12:41 PM
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..
  #4 (permalink)  
Old December 25th, 2012, 03:26 AM
Registered User
 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your information





Similar Threads
Thread Thread Starter Forum Replies Last Post
For loop with Floating Point Loop Counter - pp. 150 shivesh BOOK: Ivor Horton's Beginning Visual C++ 2010 1 March 28th, 2012 09:31 AM
Array Loop skipping loop in VBA jeskit Access VBA 5 March 20th, 2012 10:03 AM
Loop twice, then inside loop select nodes?? JohnBampton XSLT 2 March 9th, 2009 05:21 AM
while loop mikedeepak Classic ASP Professional 3 October 11th, 2005 03:34 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.