Background color of cell in Excel [Solved/Closed]

Dancing Waves - Dec 17, 2008 at 03:32 PM - Latest reply:  Pankaj
- Jun 25, 2010 at 07:53 AM
Hello,
I am trying to write a simple formula that will give me the backgroud color of a cell (in Excel). Something along the lines of, if background color is black, enter text from cell into another cell.

Does anyone have any suggestions?

Thanks
See more 

3 replies

Best answer
3
Thank you
The following Javascript code will help you change the background-color of your web-page automatically and at a time-interval (in milli-seconds) as specified in the code.

<head>
<script type="text/javascript" language="javascript">


/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */

function bgDisco()
{
var x =Math.round(255*Math.random());

var num1 =getHex(x);

var y =Math.round(255*Math.random());

var num2 =getHex(y);

var z =Math.round(255*Math.random());

var num3 =getHex(z);

document.body.style.background="#"+num1+num2+num3;

setTimeout("bgDisco()",1000);
}

/* Method To Convert Decimal To Hexadecimal */

function getHex(dec)
{
var hexArray = new Array( "0", "1", "2", "3","4", "5", "6", "7","8", "9", "A", "B","C", "D", "E", "F" );

var code1 = Math.floor(dec / 16);

var code2 = dec - code1 * 16;

var decToHex = hexArray[code2];

return (decToHex);
}
</script>
</head>

Eliza

Thank you, eliza81 3

Something to say? Add comment

CCM has helped 1665 users this month

Best answer
3
Thank you
The following Javascript code will help you change the background-color of your web-page automatically and at a time-interval (in milli-seconds) as specified in the code.

<head>
<script type="text/javascript" language="javascript">


/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */

function bgDisco()
{
var x =Math.round(255*Math.random());

var num1 =getHex(x);

var y =Math.round(255*Math.random());

var num2 =getHex(y);

var z =Math.round(255*Math.random());

var num3 =getHex(z);

document.body.style.background="#"+num1+num2+num3;

setTimeout("bgDisco()",1000);
}

/* Method To Convert Decimal To Hexadecimal */

function getHex(dec)
{
http://www.mindfiresolutions.com/...

Thank you, elizas 3

Something to say? Add comment

CCM has helped 1665 users this month

2
Thank you
Please look at the below code, I wrote it for formatting excel cells. Its not as fast as u may think of, since it happens on client side. other disadvanatage is, the client needs to have excel on the machine, otherwise it will fail...

function CreateExcelSheet()
{
var x=dataTable.rows

var xls = new ActiveXObject("Excel.Application")
xls.visible = true
var newBook = xls.Workbooks.Add
newBook.Worksheets.Add;

var row,col,rangRow, rangCol;
var colSelector = document.getElementById("colSelector").value;

row = x[0].cells.length;
col = x.length;

for (i = 0; I < x.length; i++)
{
var y = x[i].cells

for (j = 0; j < y.length; j++)
{
xls.Cells( i+1, j+1).Value = y[j].innerText;
xls.ActiveCell.EntireRow.Font.Bold = true;
xls.ActiveCell.EntireRow.Font.ColorIndex = 2;
}
}
xls.Cells.Select
xls.Cells.EntireColumn.AutoFit

if(row == 7)
rangRow = "A1"+":"+"G"+"1";
else if(row == 8)
rangRow = "A1"+":"+"H"+"1";
else if(row == 9)
rangRow = "A1"+":"+"I"+"1";
else if(row == 10)
rangRow = "A1"+":"+"J"+"1";
else if(row == 11)
rangRow = "A1"+":"+"K"+"1";

xls.range(rangRow).Select;
xls.Selection.Interior.ColorIndex = 53;
//xls.Selection.Interior.Pattern = xlSolid;

for(k=2; k<=col;k++)
{
if(colSelector == 'ticker')
{
rangCol = "A"+k+":"+"A"+k;
}
else if(colSelector == 'fund')
{
rangCol = "A"+k+":"+"A"+k;
}
else if(colSelector == 'companyName')
{
rangCol = "B"+k+":"+"B"+k;
}
else if(colSelector == 'coupon')
{
rangCol = "C"+k+":"+"C"+k;
}
else if(colSelector == 'maturity')
{
rangCol = "D"+k+":"+"D"+k;
}
else if(colSelector == 'numshares')
{
rangCol = "E"+k+":"+"E"+k;
}
else if(colSelector == 'notional')
{
rangCol = "F"+k+":"+"F"+k;
}
else if(colSelector == 'securityType')
{
rangCol = "G"+k+":"+"G"+k;
}
else if(colSelector == 'cusip')
{
rangCol = "H"+k+":"+"H"+k;
}
else if(colSelector == 'putcall')
{
rangCol = "I"+k+":"+"I"+k;
}
else if(colSelector == 'filingDate')
{
rangCol = "J"+k+":"+"J"+k;
}
else if(colSelector == 'positionDate')
{
rangCol = "K"+k+":"+"K"+k;
}
xls.range(rangCol).Select;
if(k%2!=0)
xls.Selection.Interior.ColorIndex = 36;
else
xls.Selection.Interior.ColorIndex = 15;
//xls.Selection.Interior.Pattern = xlSolid;
}
newBook.Worksheets(1).Name="13F Filing";
newBook.Worksheets(1).SaveAs("h:\\java\\13F Filing.xls");
}