Thanks:  0
Likes:  0
Dislikes:  0

1. ## Loop through Arrays

I have the following sample.
sDate = date
Edate = "27/05/2009"
Dim aColVals(5)
aColVals(0) = "23/05/2007"
aColVals(1) = "25/05/2007"
aColVals(2) = "26/05/2007"
aColVals(3) = "27/05/2007"
aColVals(4) = "28/05/2009"
Dim bColVals(5)
bColVals(1) = "200,000"
bColVals(2) = "200,000"
bColVals(3) = "200,000"
bColVals(4) = "200,000"
bColVals(5) = "200,000"

iTotal = 0

For i = 0 To UBound(aColVals)

If aColVals(i) &lt;= Edate Then
'If DateDiff("d", aColVals(i), sDate) &lt; 0 Then
iTotal = iTotal + CDbl(bColVals(i))
msgbox iTotal
End If

Next

If iTotal &gt; 0 Then
MsgBox iTotal
End If

whats the best way to loop through this array starting from Today or greater without using the values of dates older than today.

2. ## Re: Loop through Arrays

Unless you know (in advance) what index contains today's date, you probably cannot start from today.

What you can do is this:

For i = 0 To UBound(aColVals)
If i &gt;= date() Then
End If
Next

This way it flies through your array quickly, skipping everythiing that is prior to today, and doesn't execute any code until it finds a date in your array &gt;= today's date.

3. ## Re: Loop through Arrays

Thanks for the post. I nned to skip anything berfore today till an end date that i have declared as a varaiable

4. ## Re: Loop through Arrays

this is what i used
Dim mydate(5)
mydate(0) = "10/05/2007"
mydate(1)= "25/05/2007"
mydate(2)= "27/05/2007"
mydate(3)= "23/05/2007"
mydate(4)= "26/05/2007"
mydate(5)= "24/05/2007"
Dim amount(5)
amount(0)= 100.56
amount(1)= 200.24
amount(2)= 300.77
amount(3)= 400.78
amount(4)= 200.02
amount(5)= 150.78
Dim edate
Dim sdate
edate = "28/05/2007"
sdate="24/05/2007"

iTotal = 0

For i = 0 To UBound(mydate)

If mydate(i) &gt;= sdate Then

If mydate(i) &lt;= Edate Then
'If DateDiff("d", aColVals(i), sDate) &lt; 0 Then
iTotal = iTotal + CDbl(amount(i))
End If

End if

Next

If iTotal &gt; 0 Then

MsgBox cint(iTotal)
End If

5. ## Re: Loop through Arrays

Why not combine these two lines;

If mydate(i) &gt;= sdate Then

If mydate(i) &lt;= Edate Then

into

If mydate(i) &gt;= sdate And mydate(i) &lt;= Edate Then

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.