Coloring specific cell in excel of a sheet
8 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Image Analyst
on 16 Oct 2015
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 Comments
Image Analyst
on 16 Oct 2015
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?
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!