Error while using WB.Workshe​ets.Item.R​ange(varia​ble).Inter​ior.ColorI​ndex to set color of excel cell

3 views (last 30 days)
Hi,
I am getting an error when using a variable to specify the range of cells I want the color changed in my excel spreadsheet. The output of the variable I specified is 'D13:V13'. If I manually enter the same range then it works correctly. Any help would be appreciated!
Excel = actxserver('excel.application');
Excel.visible = 1;
WB = Excel.Workbooks.Open(file,0,false);
file = 'C:\Users\sz888331\Desktop\Matlab\test.xls'
range = 'D4:D400';
range2 = 'V4:V400';
data = xlsread(file,4,range);
excelrange = (4:1:size(data)+3);
excelrange = strread(num2str(excelrange),'%s');
[num ,txt, raw] = xlsread(file,4,range2);
data2 = txt;
for i = 1 : size(data)
element = data(i);
modtype = data2(i);
if element > 1920
modulation = strcmp(modtype,'12RB10MHZ')
if modulation == 1
rangestart = strcat('D',excelrange(i));
rangestop = strcat('V',excelrange(i));
fullrange = strcat(rangestart,':',rangestop)
WB.Worksheets.Item(4).Range(fullrange).Interior.ColorIndex = 12;
end
end
end
WB.Save();
WB.Close();
Excel.Quit();
I get the following error: Error using Interface.000208D8_0000_0000_C000_000000000046/Range Error: Object returned error code: 0x800A03EC
Error in Post_Process_Summ (line 21) WB.Worksheets.Item(4).Range(fullrange).Interior.ColorIndex = 12;
Thanks for the help!

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!