Michelle Deigh
New Member
- Joined
- Jan 24, 2013
- Messages
- 17
Below I have the code and pseudo code for the Case portion which is my problem - I am unsure how to word it properly - I have looked up and read hundreds of examples but keep seeing different formats so get more confused.
Basically I am doing the same thing over and over - but with new cols. To start off I have it clean and simple which as you see is done, but then I have to take the next set of numbers and if they have a negative total do one thing and if it is positive do another. After that I just update it with the same code referring to different columns.
I hope you can understand it as I really have no more description then that! Hopefully the code below will assist!
Sub PopCol()
Range("D3:D19").Formula = "=RC[-1]-RC[-2]" 'D=C-B , Delta is equal to Cap minus Dem
For i = 3 To 19
Range("D" & i) = CLng(Range("C" & i) - Range("B" & i))
If (Range("D" & i) < 0) Then
Range("E" & i) = Range("E" & i) - Range("D" & i)
Else
Range("F" & i) = Range("F" & i) + Range("D" & i)
End If
Next
Range("G3:G19").Formula = "=RC[-1]-RC[-2]" 'G=F-E , Delta is equal to Cap minus Dem
'if delta (h)= capacity (G) continue, if g<0 go back over prior months to where is negative and add to capacity
'then recalculate, else g>0 - go back over prior months and subtract(a neg) from demand (same as adding absolute value). then recalculate all.
For i = 3 To 19
Range("G" & i) = CLng(Range("F" & i) - Range("E" & i))
Select Case "May "
'Case "G" = Range ("F" & i) Continue
'Case "G" < "0" check D if >0,("D"&i)=("D"&i)-("G" & i) {then compare D with C, balance over equal is placed in G and D & C end up equal. goto beginning of sub}
'case "G" > "0" check D if <0,("C"&i)=("C"&i)-("G" & i) (then compare D with C, balance over equal is placed in G and D & C end up equal.goto beginning of sub}
End Select
'next is June......
Basically I am doing the same thing over and over - but with new cols. To start off I have it clean and simple which as you see is done, but then I have to take the next set of numbers and if they have a negative total do one thing and if it is positive do another. After that I just update it with the same code referring to different columns.
I hope you can understand it as I really have no more description then that! Hopefully the code below will assist!
Sub PopCol()
Range("D3:D19").Formula = "=RC[-1]-RC[-2]" 'D=C-B , Delta is equal to Cap minus Dem
For i = 3 To 19
Range("D" & i) = CLng(Range("C" & i) - Range("B" & i))
If (Range("D" & i) < 0) Then
Range("E" & i) = Range("E" & i) - Range("D" & i)
Else
Range("F" & i) = Range("F" & i) + Range("D" & i)
End If
Next
Range("G3:G19").Formula = "=RC[-1]-RC[-2]" 'G=F-E , Delta is equal to Cap minus Dem
'if delta (h)= capacity (G) continue, if g<0 go back over prior months to where is negative and add to capacity
'then recalculate, else g>0 - go back over prior months and subtract(a neg) from demand (same as adding absolute value). then recalculate all.
For i = 3 To 19
Range("G" & i) = CLng(Range("F" & i) - Range("E" & i))
Select Case "May "
'Case "G" = Range ("F" & i) Continue
'Case "G" < "0" check D if >0,("D"&i)=("D"&i)-("G" & i) {then compare D with C, balance over equal is placed in G and D & C end up equal. goto beginning of sub}
'case "G" > "0" check D if <0,("C"&i)=("C"&i)-("G" & i) (then compare D with C, balance over equal is placed in G and D & C end up equal.goto beginning of sub}
End Select
'next is June......