필터 지우기
필터 지우기

Coloring specific cell in excel of a sheet

조회 수: 4 (최근 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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by