Reputation: 7107
I am trying ti fill arrays based on conditions, and it seems my sample code is sticking values in the wrong position. I included the position where it is being altered. I tried doing some basic +1/-1 fixes but so far all these efforts have misplaced things or returned various other errors.
to be more clear- the issue is that in the v loop, the value is being stuck in the (o,0) position instead of the (o,v) position (over writing the previous value).
I thought the way I had it structured would for each loop perform o's criteria and then check for v's criteria and in turn when v would loop would enter the value in the v position that is equal to the current value of o?
Im clearly missing something and any pointers in the correct direction would be gladly appreciated
Dim Cbox(9, 1)
For o = LBound(Cbox, 1) To UBound(Cbox, 1)
If LPDif2 = 0 Then
Cbox(o, 0) = 0
ElseIf LPDif2 < 3 And LPDif2 > 0 Then
CCount = CCount + LPDif2
Cbox(o, 0) = LPDif2
Else
CCount = CCount + 3
Cbox(o, 0) = 3
LPDif2 = CNLP - CCount
End If
LPDif2 = CNLP - CCount
If CCount = CNLP Then BCount = BCount + 1
WCount = WCount + CW
If CCount < CNLP And CCount >= Round(CLng(CNLP) / 2 + 0.000001, 0) Then DCount = DCount + 1
If CCount >= CNLP Then DCount = DCount + 2
For v = LBound(Cbox, 2) To UBound(Cbox, 2)
If CCount >= Round(CLng(CNLP) / 2 + 0.000001, 0) And DCount = 1 Then
Cbox(o, v) = "Green"
If CTCombo = "9 W" Then
AXWCount = WCount / 2
WH.Value = Ceiling(AXWCount, 9)
Else
WH.Value = WCount
End If
End If
Next v
Next o
Upvotes: 0
Views: 27
Reputation: 22185
Based on the comments, the code inside of the inner loop should only be running if the value of v
is 1. It should be as simple as just eliminating the inner loop entirely and hard coding the value "1":
For o = LBound(Cbox, 1) To UBound(Cbox, 1)
'...
If CCount >= Round(CLng(CNLP) / 2 + 0.000001, 0) And DCount = 1 Then
Cbox(o, 1) = "Green"
If CTCombo = "9 W" Then
AXWCount = WCount / 2
WH.Value = Ceiling(AXWCount, 9)
Else
WH.Value = WCount
End If
End If
Next o
Upvotes: 1