Coloring specific cell in excel of a sheet
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Image Analyst
il 16 Ott 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 Commenti
Image Analyst
il 16 Ott 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?
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!