0% found this document useful (0 votes)
43 views9 pages

Looping in VBA - Controlling The Flow of Code: What You Learn

The document discusses various looping techniques in VBA including For...Next loops, Do...Until loops, Do...While loops, and using the Find method. It provides examples of conditionally adding values with For...Next loops, looping through text to extract values to separate cells, and ensuring proper input with a Do loop. The activity involves looping through a workbook to document all comments on a new sheet, including the author, content, and cell address of each comment.

Uploaded by

nick gomez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views9 pages

Looping in VBA - Controlling The Flow of Code: What You Learn

The document discusses various looping techniques in VBA including For...Next loops, Do...Until loops, Do...While loops, and using the Find method. It provides examples of conditionally adding values with For...Next loops, looping through text to extract values to separate cells, and ensuring proper input with a Do loop. The activity involves looping through a workbook to document all comments on a new sheet, including the author, content, and cell address of each comment.

Uploaded by

nick gomez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 9

What you learn Looping in VBA - Controlling the Flow of Code

Link Topic Covered What you Learn

ForNext For…Next Loops to run ● Simple For…Next to conditionally add values


your code many times ● Loop through text and extract text and numbers to
separate cells
● Loop through text and extract text and numbers to
separate cells

Do Do Until….Do While Loop ● Different methods to use the Do…Until Loop


● Use Do Loop to get proper input for input box
Find Use the FIND Method for Use Find method instead of looping for faster results.
Quicker Search Results
Activity Activity: Document all Loop through the workbook and document all
Comments in Workbook in comments in a new sheet - including the author, the
one place content and the cell address.
For…Next Loops to run your code many times

● Simple For…Next to conditionally add values (10) to Quantities greater than 400
● Loop through text and extract text and numbers to separate cells
● Delete Hidden / Filtered rows

Company Sales Customer Article Sales


ID Document Document Date code code Quantity Value
AT1030 84030 10/7/2018 8050 120 130 6960
AT1030 84030 10/7/2018 8050 104 530 5160
AT1030 84030 10/7/2018 8050 105 130 1200
AT1030 84030 10/7/2018 8050 107 740 3450
AT1030 84031 10/8/2018 8040 104 920 10440
AT1030 84031 10/8/2018 8040 107 810 3800
AT1030 84031 10/8/2018 8040 110 550 30000
AT1030 88112 10/11/2018 8040 110 530 28800
AT1030 88112 10/11/2018 8040 119 690 39060
AT1030 88112 10/11/2018 8040 120 150 8700
AT1030 88112 10/11/2018 8040 116 810 4560
AT1030 88112 10/11/2018 8040 111 640 11800
1030SE6 88112 10/11/2018 8040 110 570 31800
1030SE6 88112 10/11/2018 8040 109 260 7280
1030SE6 85442 10/15/2018 8050 107 270 1350
1030SE6 85442 10/15/2018 8050 103 670 7560
1030SE6 85442 10/15/2018 8050 104 470 5280
1030SE6 85442 10/15/2018 8050 120 530 29000
1030SE6 85442 10/15/2018 8050 119 360 22320
1030SE6 85442 10/15/2018 8050 115 840 4860
1030SE6 85442 10/15/2018 8050 108 830 22400
1030SE6 88588 10/15/2018 8040 120 500 27260
1030SE6 88588 10/15/2018 8040 119 890 53320
1030NL40 88588 10/15/2018 8040 110 180 10800
1030NL40 88588 10/15/2018 8040 111 780 15000
1030NL40 88588 10/15/2018 8040 109 590 15680
1030NL40 88588 10/15/2018 8040 105 130 1300
1030NL40 88588 10/15/2018 8040 103 110 1320
1030NL40 88544 10/22/2018 8040 107 800 3850
1030NL40 88544 10/22/2018 8040 120 300 17400
1030NL40 88666 10/26/2018 8030 119 330 20460
1030NL40 88666 10/26/2018 8030 107 490 2300
1030NL40 88666 10/26/2018 8030 105 500 4700
1030AT 88666 10/26/2018 8030 115 390 2340
1030AT 88666 10/26/2018 8030 116 260 1560
1040DE 44030 10/4/2018 8060 108 60 1680
1040DE 44030 10/4/2018 8060 109 60 1680
1040DE 44032 10/7/2018 8060 108 60 1680
1040DE 44032 10/7/2018 8060 109 70 1960
1040DE 44031 10/8/2018 8050 108 60 1680
1040DE 44031 10/8/2018 8050 109 50 1400
1040DE 44031 10/8/2018 8050 110 60 3600
1040DE 48112 10/11/2018 8060 109 60 1680
1040DE 48112 10/11/2018 8060 110 50 3000
1040DE 48114 10/11/2018 8050 109 60 1680
1040DE 48114 10/11/2018 8050 110 60 3600
1040DE 48114 10/11/2018 8050 111 80 1600
1040DE 48116 10/11/2018 8060 109 60 1680
1040DE 48116 10/11/2018 8060 110 60 3600
1040DE 45442 10/15/2018 8050 108 50 1400
1040DE 45442 10/15/2018 8050 109 60 1680
1040DE 45444 10/15/2018 8060 108 60 1680
1040DE 45444 10/15/2018 8060 109 70 1960
1040DE 45444 10/15/2018 8060 110 60 3600
1040DE 45446 10/15/2018 8050 111 80 1600
1040DE 45446 10/15/2018 8050 108 50 1400
1040DE 44015 10/10/2018 8060 108 60 1680
1040DE 44015 10/10/2018 8060 109 70 1960
1040DE 44017 10/13/2018 8060 108 70 1960
1040DE 44017 10/13/2018 8060 109 70 1960
1040DE 44016 10/14/2018 8050 108 70 1960
1040DE 44016 10/14/2018 8050 109 60 1680
1040DE 44016 10/14/2018 8050 110 50 3000
1040DE 48097 10/17/2018 8060 109 60 1680
1040DE 48097 10/17/2018 8060 110 70 4200
1040DE 48099 10/17/2018 8050 109 60 1680
1040DE 48099 10/17/2018 8050 110 60 3600
1040DE 48099 10/17/2018 8050 111 60 1200
1040DE 48101 10/17/2018 8060 109 60 1680
1040DE 48101 10/17/2018 8060 110 50 3000
1040DE 45427 10/21/2018 8050 108 70 1960
1040DE 45427 10/21/2018 8050 109 60 1680
1040DE 45429 10/21/2018 8060 108 80 2240
1040DE 45429 10/21/2018 8060 109 80 2240
1040DE 45429 10/21/2018 8060 110 50 3000
1040DE 45431 10/21/2018 8050 111 60 1200
1040DE 45431 10/21/2018 8050 108 60 1680
Do Until….Do While Loop
● Different methods to use the Do…Until Loop
● Example of Do…While Loop

Quantity Add 10 Add 10 Add 10


(Do Until) (Do While) (Exit Do)
530
530
160
730
910
800

● Create an Input Box that requires a Number Input.


- The user can't close the input box, until a number value is input
Use the FIND Method for Quicker Search Results
One Match: Many Matches:
Find Article
Code for this
entity: 1030SE6

Sales Document Article Sales


Company ID Document Date Customer code code Quantity Value
AT1030 84030 10/7/2018 8050 120 130 6960
1030SE6 84030 10/7/2018 8050 104 500 5160
1030SE6 84030 10/7/2018 8050 105 130 1200
AT1030 84030 10/7/2018 8050 107 710 3450
SE1080 84031 10/8/2018 8040 104 890 10440
DE1030 84031 10/8/2018 8040 107 780 3800
DE1030 84031 10/8/2018 8040 110 520 30000
AT1030 88112 10/11/2018 8040 110 500 28800
SE1080 88112 10/11/2018 8040 119 660 39060
SE1080 88112 10/11/2018 8040 120 150 8700
1030SE6 88112 10/11/2018 8040 116 780 4560
AT1030 88112 10/11/2018 8040 111 610 11800
1030SE6 88112 10/11/2018 8040 110 540 31800
From MSDN.Microsoft.com
Activity: Document all Comments in Workbook in one place

Create a macro which provides a summary report of all comments in a Workbook in a separate sheet.
What the macro should do:
● Create a new sheet
● Put header "Comment", "Address" & "Author" in A1, B1 & C1 respectively.
● Put the content of each comment in the workbook in a separate cell - starting from A2.
● Put the address of each comment - such as the worksheet name and cell address in a separate cell starting from B2 and a

Answer is in the completed Workbook in Module "ProjectActivity"


ate cell starting from B2 and author from C2.

You might also like