• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
For Next Looping In Excel Vba
 

For Next Looping In Excel Vba

on

  • 3,615 views

For next looping works by using a counter variable. The counter states the number of times a specific piece of code should be repeated.

For next looping works by using a counter variable. The counter states the number of times a specific piece of code should be repeated.

Statistics

Views

Total Views
3,615
Views on SlideShare
3,611
Embed Views
4

Actions

Likes
0
Downloads
35
Comments
0

1 Embed 4

http://www.slideshare.net 4

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    For Next Looping In Excel Vba For Next Looping In Excel Vba Presentation Transcript

    • For-Next Looping in Excel VBA Microsoft Office Training Excel Training www.bluepecan.co.uk
    • • 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
    • • 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
    • 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
    • • 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
    • 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
    • • 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
    • 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
    • • See this Excel training tutorial on the Blue Pecan website www.bluepecan.co.uk