答案 0 :(得分:0)
您正在寻找Range.SpecialCells method。
public partial class Form1: Form
{
int x = 25, y = 1;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.SetBounds(x, y, 255, 255);
x++;
if (x >= 800)
{
x = 1;
}
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = "hii";
label1.Font = new Font(" ", 22, FontStyle.Bold);
timer1.Interval = 10;
timer1.Start();
}
}
为您提供所有常数.SpecialCells(xlCellTypeConstant, xlNumbers)
500
为您提供所有带数字作为结果的公式.SpecialCells(xlCellTypeFormulas, xlNumbers)
或SUM(C8:C13)
请注意,如果找不到指定类型的单元格,SUM(C8:C13)+522
将引发错误。因此,您需要检查此。通过抑制错误并检查SpecialCells
的设置变量:
Nothing
答案 1 :(得分:-1)
您可以使用SpecialCells
方法在范围内选择某些单元格类型。具有公式的单元格为xlCellTypeFormulas
,具有“硬编码”值的单元格为xlCellTypeConstants
Sub ColorCellsByType(Target As Range, FormulaColour As Long, ConstantColour As Long)
On Error GoTo NoFormula 'Skip line if there is a "no cells" error
Target.SpecialCells(xlCellTypeFormulas).Interior.Color = FormulaColour
NoFormula:
On Error GoTo NoComments 'Skip line if there is a "no cells" error
Target.SpecialCells(xlCellTypeConstants, xlNumbers).Interior.Color = ConstantColour 'Does not include Text values
NoComments:
On Error GoTo 0 'Show error messages, so you can fix them
End Sub
您的“第3部分”毫无意义,因为=SUM(C8:C13)+552
只是一个常规公式-您的意思是添加了常量的 Function 吗?
答案 2 :(得分:-3)
有一个HasFormula
测试可以运行。
您需要选择范围,然后运行宏或将For each cel in Selection
更改为For each cel in [A1:B25]
(将[A1:B25]
更改为所需的范围)
Sub CheckFormulas()
Dim cel as Range
For each cel in Selection
If cel.HasFormula then
’Whatever you want to do the formula cell here
Else
’Whatever you want to do to the non formula cell here
End if
Next cel
End sub