2011-07-01 313 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 
相关问题