在特定单元格中填充颜色

Put a fill color in a specific cell

我的程序循环遍历 sheet 中的每一行数据。然后当它出错时,我想在那个特定的单元格上填充颜色。

有没有办法在不使用范围的情况下在单元格中填充颜色?

 On Error GoTo Stop

  'doing something

 Exit Sub
Stop:
Msgbox("Error!")

'something like this to fill the cell
Sheets("Data").Cells(rowdata,1).Color = red

你可以这样做

Cells(rowindex, columnindex).interior.color = RGB-code

cells(rowindex, columnindex).interior.colorindex = indexno