急 谁来看下 这是为什么
//添加验证功能,在每次新增时后去将当前currentrange获取为当前范围,然后通过条件选择的公式追加突出显示的功能//
////////////////////新增一条记录后,用户对新增的记录做修改的同时,此突出显示将会生效///////////////////////
Excel.Worksheet ws = Globals.ThisWorkbook.Worksheets[5];
Range current_rang = ListKey.Range;
if (current_rang.FormatConditions.Count > 0)
{
current_rang.FormatConditions.Delete();
}
object mis = System.Type.Missing;
int count = current_rang.CurrentRegion.Rows.Count;
Range selectionrange = ws.Range[ws.Cells[7, 2], ws.Cells[count+5, 4]];
string text = "=SUMPRODUCT(($B$7:$B$" + (count+5).ToString() + "=$B7)*($C$7:$C$" + (count+5).ToString() + "=$C7)*($D$7:$D$" + (count+5).ToString() + "=$D7))>1";
Excel.FormatCondition cond =
(Excel.FormatCondition)selectionrange.FormatConditions.Add(Excel.XlFormatConditionType.xlExpression,
Excel.XlFormatConditionOperator.xlEqual,text,
mis,mis, mis,mis,mis);
cond.ModifyAppliesToRange(ws.Range[(Excel.Range)ws.Cells[7, 4], (Excel.Range)ws.Cells[count+5, 4]]);
//cond.Interior.PatternColorIndex = Excel.Constants.;
cond.Interior.TintAndShade = 0;
cond.Interior.Color = XlRgbColor.rgbGreenYellow;
cond.StopIfTrue = true;
代码如上用C#改的,请VB同学们看下帮帮忙 调了很久就是调试不出哪里发生的变化;实际效果在excel条件选择的规则中 我代码写死的规则却发生了变化,如下图
--------------------编程问答-------------------- 自己先顶下!
补充:VB , VBA