Coloring specific cells with Excel VBA off by one cell -
i'm generating excel worksheet based on entries in userform. 1 entry reporting interval on project duration. let's reporting interval 3 months , duration of phase2 10 months , phase3 3 months.
my columns structured distance of 1 cell between phases:
phase1: starting phase phase2: working phase phase3: closing phase phase1 phase2 phase3 |||||| ||||||||||||||||||||||||||| ||||||
the reporting intervals should marked colored cells in phase2 , phase3 this:
phase1 phase2 phase3 |||||| |||||||o|||||||||||o|||||||| ||o||||
this code color cells:
for x = 1 (implementationduration + closingduration - 1) / 3 select case x case < implementationduration: call setfontandbackground(cells(rowindex, phase1celllast() + columncounter * 3), cells(rowindex, phase1celllast() + columncounter * 3), false, false, "", 10, false, "b", "lcyan", false) columncounter = columncounter + 4 case > 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
problem colored cells in phase3 not correctly positioned. off 1 cell. coloring use subroutine formatting cells. cannot find mistake in code.
found problem. select case statements incorrect. has be:
for x = 1 (phase2duration + phase3duration - 1) / 3 phase2range = phase1celllast() + columncounter * 3 select case phase2range case < phase2celllast(): call setfontandbackground(cells(rowindex, phase1celllast() + columncounter * 3), cells(rowindex, phase1celllast() + columncounter * 3), false, false, "", 10, false, "b", "lcyan", false) columncounter = columncounter + 4 case > 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
Comments
Post a Comment