Coloring specific cell in excel of a sheet

7 ビュー (過去 30 日間)
Praveen Choudhury
Praveen Choudhury 2015 年 10 月 16 日
コメント済み: Image Analyst 2015 年 10 月 16 日
I have an excel sheet of 23 rows and 44 columns. I want to do a string comparison of row 2 and 3,row 6 and 7,row 10 and 11. When the strings are not same, I want to color both with red. And I want these changes to be pasted in a different sheet in that excel file. Find here attached my excel sheet for reference.

回答 (1 件)

Image Analyst
Image Analyst 2015 年 10 月 16 日
Use ActiveX - see attached demo if you need to know how to do that. To color a cell in Excel:
%-------------------------------------------------------------------------------------------------------
% Fills the background color of the Excel cell with the specified color.
% Sample call:
% Set the color of cell "A1" of Sheet 1 to Yellow
% FormatCellColor(Excel, cellReference, 6)
function FormatCellColor(Excel, cellReference, cellFillColorIndex)
try
Excel.Worksheets.Item(1).Range(cellReference).Interior.ColorIndex = cellFillColorIndex;
catch ME
errorMessage = sprintf('Error in function FormatCellColor.\n\nError Message:\n%s', ME.message);
fprintf('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end % from FormatCellColor
return;
end
  2 件のコメント
Praveen Choudhury
Praveen Choudhury 2015 年 10 月 16 日
The problem I am facing is with the cell value. I want the cell value to be dynamical.
Image Analyst
Image Analyst 2015 年 10 月 16 日
There's a similar method for the font color - the color of the value or number in the cell. It might be something like
Excel.Worksheets.Item(1).Range(cellReference).ForeColor.ColorIndex
or something similar. Why don't you record a macro and see what it is?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by