For Next Looping In Excel Vba

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    For Next Looping In Excel Vba - Presentation Transcript

    1. For-Next Looping in Excel VBA Microsoft Office Training Excel Training www.bluepecan.co.uk
    2. • For next looping works by using a counter variable. The counter states the number of times a specific piece of code should be repeated. www.bluepecan.co.uk
    3. • The following macro produces a random number between 1 and 100. The code includes a counter which will run the code 100 times offsetting each value by one row – in other words creating the values down a column. www.bluepecan.co.uk
    4. Sub CountExample() Dim Counter As Integer For Counter = 1 To 100 ActiveCell.Value = Int (Rnd*100) ActiveCell.Offset(1, 0).Select Next Counter End Sub www.bluepecan.co.uk
    5. • A step value can be included in a For-Next Loop. The step value determines how the counter is incremented. Change the active cell value to Counter to see the increment more clearly www.bluepecan.co.uk
    6. Sub CountExample() Dim Counter As Integer For Counter = 1 To 100 Step 5 ActiveCell.Value = Counter ActiveCell.Offset(1, 0).Select Next Counter End Sub www.bluepecan.co.uk
    7. • The macro might be more useful if the user can give their own counter and step values. We will introduce a couple of input boxes for this purpose: www.bluepecan.co.uk
    8. Sub CountExample2() Dim Counter As Integer Dim ToNum As Integer Dim StepNum As Integer ToNum = InputBox("What maximum value do you want?") StepNum = InputBox("What increment do you want?") For Counter = 1 To ToNum Step StepNum ActiveCell.Value = Counter ActiveCell.Offset(1, 0).Select Next Counter End Sub www.bluepecan.co.uk
    9. • See this Excel training tutorial on the Blue Pecan website www.bluepecan.co.uk

    + Chester TugwellChester Tugwell, 4 months ago

    custom

    741 views, 0 favs, 0 embeds more stats

    For next looping works by using a counter variable. more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 741
      • 741 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 10
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories