+ Reply to Thread
Results 1 to 6 of 6

Using for and next options in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    02-01-2018
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    18

    Using for and next options in VBA

    Hi all,

    I am in learning phase of VBA.

    My task is simple. Please refer the attached images (Image 1 and Image 2).

    My cell B1 is 2, B2 is based on " i " value (initial i value is 2)

    if i add B1 and B2 in B3, the output should be 10.
    Until the addition becomes 10, the value of B2 have to be changed in the increment of 1 (i.e. i + 1)

    I have tried a code of my own. But i am facing errors.

    Please help me in resolving this.


    Thanks,
    Prabhu P

    Image 1.PNGImage 2.PNG

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Using for and next options in VBA

    Attach your workbook, rather than an image.

    Go Advanced -> Manage Attachments -> Upload

  3. #3
    Registered User
    Join Date
    09-12-2018
    Location
    Britain
    MS-Off Ver
    2010
    Posts
    5

    Re: Using for and next options in VBA

    1. The assignment of variable "c" seems redundant in your code.
    2. B3 has never been assigned with a value.
    3. The "IF...THEN...ELSE..." structure is not a loop but executes only once. Even if it's written properly it does increment the value of B2 from 2 to 3, but not up to 8 to make up with a total of 10. (if I understand your question correctly).
    Instead, you may use "Do while loop" or "Do until loop" to execute the part of code for increment (which is potentially executed more than once).

  4. #4
    Registered User
    Join Date
    02-01-2018
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    18

    Re: Using for and next options in VBA

    Hi kersplash,
    sorry, the file have been uploaded in the previous comment. Can you please use it..

  5. #5
    Registered User
    Join Date
    02-01-2018
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    18

    Re: Using for and next options in VBA

    Hi Pensis,
    yes, you are upto my requirement.
    Can you please write a code to execute the task.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-12-2018
    Location
    Britain
    MS-Off Ver
    2010
    Posts
    5

    Re: Using for and next options in VBA

    Quote Originally Posted by prabhu04 View Post
    Hi Pensis,
    yes, you are upto my requirement.
    Can you please write a code to execute the task.
    Try to replace the last part of the your code with below:

    c = a + b
    
    Do While c < 10
        b = b + 1
        c = a + b
    Loop
    
    Range("b2").Value = b
    Range("b3").Value = c

+ 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] Can't find corrext Index Match formula where different options have same sub-options
    By Ochimus in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-27-2016, 06:59 AM
  2. Replies: 0
    Last Post: 08-26-2014, 08:44 AM
  3. extracting text string with 2 options @ end & limited options
    By ChristianR in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 10-24-2010, 06:51 AM
  4. Replies: 1
    Last Post: 08-11-2006, 12:00 PM
  5. Working with options from within Tools Options clears the Clipboar
    By Peter Rooney in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-18-2005, 12:55 PM
  6. [SOLVED] How to diasble the 'Tools - Options - View - Comments' options?
    By Alan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-19-2005, 07:06 PM
  7. How to set options for Auto Fill Options?
    By aijihz in forum Excel General
    Replies: 1
    Last Post: 03-28-2005, 01:24 AM

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