MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 08:25 PM   #1
finaddict
 
Join Date: Mar 2004
Location: Daphne, AL
Posts: 33
Default Is this possible?

Say you have sheet1 and sheet2. Some cells on sheet1 are shaded. On sheet2 you want, for example, cell A1 to list the cell numbers in the color the cells are shaded but without the cell letter. Just the number of the cell with the number being the color of the shaded cell. Sounds like VB coding to me and I'm not a VB guy yet. Would like to be though.

Thanks,
Steve
finaddict is offline   Reply With Quote
Old Mar 30th, 2004, 08:35 PM   #2
Cbrine
 
Cbrine's Avatar
 
Join Date: Dec 2003
Location: Brampton
Posts: 3,174
Default Re: Is this possible?

Public Function RColor(C As Range)
On Error GoTo Errorhandler

If C.Count > 1 Then Err.Number = 9999

RColor = C.Interior.ColorIndex
Exit Function


Errorhandler:
RColor = Err.Number
End Function

Paste the code to a module and us it as a formula in Sheet2 A1
=RColor(Sheet1!A1)
Then just fill down.
__________________
Xcelerated Solutions
Office Automation Solutions for the Toronto Area
Cbrine is offline   Reply With Quote
Old Mar 30th, 2004, 09:11 PM   #3
finaddict
 
Join Date: Mar 2004
Location: Daphne, AL
Posts: 33
Default Re: Is this possible?

I don't quite understand what I'm to do with the information you gave me. I'm new to this coding thing. Could you give a little more detailed instructions?

Thanks,
Steve
finaddict is offline   Reply With Quote
Old Mar 30th, 2004, 09:25 PM   #4
Cbrine
 
Cbrine's Avatar
 
Join Date: Dec 2003
Location: Brampton
Posts: 3,174
Default Re: Is this possible?

Steve,
From Excel press ALT-F11, this will open the VBA Editor.

Select View...Project Explorer

On the project explorer Right click on the
Microsoft Excel Objects Folder for the current sheet.
Select Insert...Module

Just paste the code to this new module and close the explorer(Don't worry the code is save with the workbook).

Now just type the function into the cells, like any other excel formula.

Have fun.
__________________
Xcelerated Solutions
Office Automation Solutions for the Toronto Area
Cbrine is offline   Reply With Quote
Old Mar 31st, 2004, 12:41 AM   #5
finaddict
 
Join Date: Mar 2004
Location: Daphne, AL
Posts: 33
Default Re: Is this possible?

CBrine....I couldn't get it to work but I'm sure it's my fault. But I have come up with an easier task. Let's say row1 on sheet1 has some shaded cells with a number in them. Then on sheet2 cell A1 would list all the numbers and change the color of the numbers to the color of the cell. Can that be done easier.

Thanks for being patient,
Steve
finaddict is offline   Reply With Quote
Old Mar 31st, 2004, 04:40 AM   #6
finaddict
 
Join Date: Mar 2004
Location: Daphne, AL
Posts: 33
Default Re: Is this possible?

I did like you told me but all I get in the cell is -4142.

Thanks,
Steve
finaddict is offline   Reply With Quote
Old Mar 31st, 2004, 04:00 PM   #7
Cbrine
 
Cbrine's Avatar
 
Join Date: Dec 2003
Location: Brampton
Posts: 3,174
Default Re: Is this possible?

Steve,
I think I may have misunderstood what you are looking for. The VBA code I gave you will return the colorindex number to another cell based on the source cell's background color. So if the background is white you get the number -4142.
Can you tell me what exactly you need?

Sheet1!A1= 100 Blue backgound

The formula should return to Sheet2!A1

100 and change the color of the cell to blue?

Is it the interior color or the font color?

If you want the formula to change the color of the cell, that's not possible with a function. A function can only return values to the cell. You might need to work with the WorkSheet_Change event to get the result you are looking for.

Let me know?
__________________
Xcelerated Solutions
Office Automation Solutions for the Toronto Area
Cbrine is offline   Reply With Quote
Old Mar 31st, 2004, 04:52 PM   #8
finaddict
 
Join Date: Mar 2004
Location: Daphne, AL
Posts: 33
Default Re: Is this possible?

I'll try to give a better example of what I'm trying to do. I'm not real good at explaining things but here it goes.

What I've got is a sheet (sheet1) that has selected cells which are shaded. They also have a number in those shaded cells. What I would like to do is on sheet2, starting in cell A1, list the numbers that is in the cell and each number be the same color of the cell.

For example:

Sheet1, column A has cells A44..A46 shaded black with a number in the cells. Then column B has cells B30...B42 shaded red with a number in the cells. This goes on across an entire worksheet. On sheet2 in cell A1, I would want it to read "##,##,##" in black. The "##" are the numbers in the cells. Then in cell A2 it would list the numbers in column B and the numbers would be red which is the same color of the shaded cells. In some columns there would be cells of more than one or two colors. For the rest of the sheet column C would list in A3 and so on. I hope this kinda makes some since. I need some pictures. That would probably help.

Thanks,
Steve
finaddict is offline   Reply With Quote
Old Mar 31st, 2004, 06:01 PM   #9
Cbrine
 
Cbrine's Avatar
 
Join Date: Dec 2003
Location: Brampton
Posts: 3,174
Default Re: Is this possible?

Steve,
I'm pretty sure I understand what you are looking for now. I don't think what you want is possible using VBA. I did a couple of quick tests and found, that while you can edit a cell and modify individual elements color attributes, there is no way to do that using VBA. When a cell has multiple colors, the VBA colorindex property gets set to null.

Sorry Steve.

If anyone else know how to use VBA to change a color within a cell, let us know.
ex.( 12 13 14)
__________________
Xcelerated Solutions
Office Automation Solutions for the Toronto Area
Cbrine is offline   Reply With Quote
Old Mar 31st, 2004, 06:48 PM   #10
finaddict
 
Join Date: Mar 2004
Location: Daphne, AL
Posts: 33
Default Re: Is this possible?

CBrine,
The example you posted is what I'm looking for. For instance 12,13,14 would be listed in cell A1 sheet2 because sheet1, column A, had cells that were shaded red, dark blue, blue with the numbers "12, 13, 14" in them and then sheet2, cell A2 would list what was in sheet1 column B and so on. I hope someone can figure out a way to do this because it would save a ton of time in typing, which I'm not very good at in the first place.

Thanks for your time CBrine,

Steve
finaddict is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 03:40 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.