2011-07-01 307 views
0

我正在根據用戶窗體中的條目生成Excel工作表。一個條目是項目期間的報告間隔。假設報告間隔爲三個月,第二階段的持續時間爲10個月,第三階段爲三個月。使用Excel VBA關閉一個單元格的特定單元格

我的專欄是結構化這樣一個單元的相位之間的距離:

Phase1: Starting phase 
Phase2: Working phase 
Phase3: Closing phase 

Phase1 Phase2      Phase3 
|||||| ||||||||||||||||||||||||||| |||||| 

的報告間隔應標記爲有色細胞的階段2和三期這樣的:

Phase1 Phase2      Phase3 
|||||| |||||||O|||||||||||O|||||||| ||O|||| 

這是我的代碼,爲單元格着色:

For x = 1 To (Implementationduration + Closingduration - 1)/3 
      Select Case x 
       Case Is < Implementationduration: 
        Call SetFontAndBackground(cells(Rowindex, Phase1CellLast() + Columncounter * 3), cells(Rowindex, Phase1CellLast() + Columncounter * 3), False, False, "", 10, False, "b", "lcyan", False) 
        Columncounter = Columncounter + 4 
       Case Is > Implementationduration: 
        Call SetFontAndBackground(cells(Rowindex, Phase1CellLast() + Columncounter * 3 + 1), cells(Rowindex, Phase1CellLast() + Columncounter * 3 + 1), False, False, "", 10, False, "b", "lcyan", False) 
        Columncounter = Columncounter + 4 
      End Select 
Next x 

問題是,co階段3中的計數單元未正確定位。他們離開一個牢房。爲了着色,我使用一個子程序來格式化單元格。我在代碼中找不到錯誤。

回答

1

發現問題。我的Select病例陳述不正確。它必須是:

For x = 1 To (Phase2duration + Phase3duration - 1)/3 
      Phase2range = Phase1CellLast() + Columncounter * 3 
      Select Case Phase2range 

       Case Is < Phase2CellLast(): 
        Call SetFontAndBackground(cells(Rowindex, Phase1CellLast() + Columncounter * 3), cells(Rowindex, Phase1CellLast() + Columncounter * 3), False, False, "", 10, False, "b", "lcyan", False) 
        Columncounter = Columncounter + 4 
       Case Is > Phase2CellLast(): 
        Call SetFontAndBackground(cells(Rowindex, Phase1CellLast() + Columncounter * 3 + 1), cells(Rowindex, Phase1CellLast() + Columncounter * 3 + 1), False, False, "", 10, False, "b", "lcyan", False) 
        Columncounter = Columncounter + 4 
      End Select 
Next x 
相關問題