Coloring specific cell in excel of a sheet

8 次查看(过去 30 天)
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?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by