2. Basic Coding Structure: Loop Within Loop
Now we've built a 'blueprint' for this VBA routine using comments in the VBA editor, we're ready to start creating the code. Note that creating the code is much easier when we have structured comments to work with! It's actually a case of 'translating' the comments to VBA, line-by-line.
With that in mind, we set about creating the code. The first job is to create the required variables (simply places to store information that helps with code execution) - this is easy enough with the annotations already there. Then, we're ready to put in the main code infrastructure - in this case, a 'loop within a loop'. We need this construct because our goal is to check each line of data for each team in the fixtures. It's incredibly powerful and has so many applications in VBA.
We set these mechanisms up with our usual 'code a bit, test a bit' approach. Did you get the mechanisms working too? Let us know in the comments below the video.
Tools And Techniques
- variable declaration
- different variable types
- for each loop
- loop within loop
- one line conditional statement
- using msgbox for testing
With that in mind, we set about creating the code. The first job is to create the required variables (simply places to store information that helps with code execution) - this is easy enough with the annotations already there. Then, we're ready to put in the main code infrastructure - in this case, a 'loop within a loop'. We need this construct because our goal is to check each line of data for each team in the fixtures. It's incredibly powerful and has so many applications in VBA.
We set these mechanisms up with our usual 'code a bit, test a bit' approach. Did you get the mechanisms working too? Let us know in the comments below the video.
Tools And Techniques
- variable declaration
- different variable types
- for each loop
- loop within loop
- one line conditional statement
- using msgbox for testing
3 Lessons