+ Reply to Thread
Results 1 to 3 of 3

If Loop Wrong Usage?

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    redwood city, ca
    MS-Off Ver
    Excel 2010
    Posts
    1

    If Loop Wrong Usage?

    I'm new to VBA, and was trying to write a simple loop code to check the value of a column of cells starting from B2 to B25 in sheet1 and if the value was greater than 0 it would go sheet2 and take the values starting in A1, multiple it by 3, and place the value in A2 and so forth. This would continue until all the cells in sheet1 were reviewed. For some reason this code will execute regardless of the value of the cells in B2 through B25. Cell B3 in sheet1 could have a -1 and yet the code will still execute. Any help would be appreciated.

    Please Login or Register  to view this content.
    Last edited by rylo; 02-23-2011 at 08:02 PM. Reason: added code tags

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: If Loop Wrong Usage?

    Hi

    The way your code is working (assuming that the typo is not in the real code), then if it finds 1 entry that is > 0, all the cells in the output sheet will be filled.

    How about putting up an example file and show what should be the result from the data in that example file.

    rylo

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: If Loop Wrong Usage?

    Im assuming that sheet 2 column A is going to be empty except for the first value, otherwise you are just going to be transposing over useless values. If they are emtpy this should work for you. If not we are going to have to change things.
    Please Login or Register  to view this content.
    On your code it might be better to use a counter inside the if statement rather than a loop in a loop. Up to you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1