After years of VBA development, I’m still learning about the language every day. I was absolutely surprised when I tried this today. You can iterate over a date range just like you can iterate over a range of integers.
Public Sub LoopOverDateRange()
Const startDate As Date = #5/13/2015#
Const endDate As Date = #5/20/2015#
Dim d As Date
Dim i As Integer
i = 1
For d = startDate To endDate
Debug.Print "Iteration " & i & ":" & vbTab & d
i = i + 1
This code will result in the following output.
Iteration 1: 5/13/2015
Iteration 2: 5/14/2015
Iteration 3: 5/15/2015
Iteration 4: 5/16/2015
Iteration 5: 5/17/2015
Iteration 6: 5/18/2015
Iteration 7: 5/19/2015
Iteration 8: 5/20/2015
I don’t normally write about my work here, but I just spent the last week in sunny Orlando, FL at JDA Software’s Focus conference. I figured I might as well sum up the experience here before its all over and begins to fade.
For those of you not familiar with JDA, they’re a software company who has a range of products spanning the entire supply chain from manufacturer right down to actually placing the product on the shelf. My work brings me into the macro and micro space planning realms. Or rather, I support the people in my company who use the Floor Planning and Space Planning software. This involves automating that software and interacting with JDA’s database product.
Did you know that there’s code in your VBA projects that you can’t see in your editor? Want to see it? (Of course you do.)