+ Reply to Thread
Results 1 to 7 of 7

Need Help With Loop Until in VBA

  1. #1
    Registered User
    Join Date
    11-03-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    9

    Question Need Help With Loop Until in VBA

    Hey guys,

    I've been starting to use VBA recently so its still pretty new to me
    Although, i do know you can use it to add to a number in specific integers until a value is reached, I'm not completely sure how to write this.

    for example

    A1=1 and B1=5

    If A1 is < B1 then A1 + .5 until A1 >= B1

    Anyone have any suggestions,
    whatever help provided would be much appreciated.

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

    Re: Need Help With Loop Until in VBA

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need Help With Loop Until in VBA

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-03-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Need Help With Loop Until in VBA

    Thanks for your responses!

    Does there happen to be a way to do this automatically?
    I've entered the codes you provided and it doesn't seem to do anything with the numbers in the cells.

    If there is a way to do this automatically, is there also a way to apply this to a command button?

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need Help With Loop Until in VBA

    Maybe:

    Please Login or Register  to view this content.
    Not really getting your point? Why not just A1 = B1. Or maybe I'm misunderstanding you.

  6. #6
    Registered User
    Join Date
    11-03-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Need Help With Loop Until in VBA

    Thanks for your help but i was able to figure it out with some external sources.

    The VBA code came out looking like this:


    Sub LoopUntil()
    Do While Range("a1") < Range("b1")
    Range("a1") = Range("a1") + 0.5
    Loop


    End Sub


    Private Sub CommandButton1_Click()
    LoopUntil
    End Sub

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

    Re: Need Help With Loop Until in VBA

    Not really getting your point? Why not just A1 = B1.
    I was thinking the same thing. The only thing I could figure he/she was doing was going to incorporate some other task into the loop.

    Or maybe they just want to get increase a decimal value to anything past five (example: 4.8 + .5 = 5.3)

    Guess we aren't mind readers. Either way, John's code will add 0.05 (i think he meant to put 0.5) one time. If that is what you want, great. If not just assign the code I gave above to a command button.

    Edit: glad you found your solution. Please mark this thread as solved
    Last edited by stnkynts; 12-11-2013 at 04:28 PM. Reason: Sometimes I just facepalm

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  2. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  3. Macro Loop Broken. Detects Max but doesn't continue loop
    By herchenbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2011, 12:17 PM
  4. Replies: 0
    Last Post: 07-20-2010, 11:42 AM
  5. Loop a column on Sheet1 and loop a row on Sheet2 to find a match
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2009, 02:09 PM

Tags for this Thread

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