非常感谢我在论坛上收到的有关此特定代码的帮助;我以为我从那里得到了它,但我必须再次请求你的帮助。我认为我能给出的最佳解释是伪代码!一旦完成这个案例选择部分,我会在几个月内重复相同的过程,因此只需要更改引用的单元格。
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 (Range("G" & i)) 'May
'Case "G" = Range ("F" & i) Continue
Case Is = Range("F" & i)
GoTo Line 35
'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 Is < "0"
("D"&i)=("D"&i)-("G" & i)else Goto Line 5
Case Else
'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}
If Range("G" & i) > "0" Then
End Select
'next is June
For i = 3 To 19
Range("J" & i) = CLng(Range("I" & i) - Range("H" & i))
Select Case "June"
'Case "H" = Range ("F" & i) Continue
'Case "H" < "0" check G if >0,("G"&i)=("G"&i)-("J" & i) {then compare G with F, balance over
equal is placed in J and G & F end up equal. goto beginning of sub}
'case "H" > "0" check G if <0,("F"&i)=("F"&i)-("J" & i) (then compare G with F, balance over equal
is placed in J and G & F end up equal. goto beginning of sub}
End Select
Next
'COntinue on with July, August, Sept, Oct, Nov, Dec, Jan 14, Feb 14 but in FEb 14 place balance over
equal in
End Sub
非常感谢SOOOO!
答案 0 :(得分:0)
你的问题很难理解。我已经发布了一个代码应该类似的示例,希望您可以填写空白。
For i = 3 To 19
Range("G" & i).Value = CLng(Range("F" & i).Value) - CLng(Range("E" & i).Value)
Select Case CLng((Range("G" & i)).Value)
Case CLng(Range("F" & i).Value)
GoTo Line 35
Case < "0"
'("D"&i)=("D"&i)-("G" & i)else Goto Line 5 <--- very wrong, use the 2nd to see reformat this line.
Case Else
GoTo Line 35
End Select
Next i