locked
Font color in the cells RRS feed

  • Question

  • Hi,
    How about the way to change the color within VBA?
    Many Thanks & Best Regards, HuaMin Chen
    Tuesday, March 16, 2010 3:19 AM

Answers

All replies

  • This might help

    Range("A6").Select
    Selection.Font.Color = 65433

    You can try to record Marco to see the coding
    • Marked as answer by Tim Li Wednesday, March 17, 2010 9:23 AM
    • Unmarked as answer by Jackson_1990 Thursday, March 18, 2010 2:37 AM
    • Marked as answer by Jackson_1990 Friday, March 26, 2010 8:52 AM
    Tuesday, March 16, 2010 8:57 AM
  • i've got the runtime error 1004 by using the way you suggested

    pls see the error here
    http://www.4shared.com/file/243526878/f5e4eb3/_2__error3.html


    Many Thanks & Best Regards, HuaMin Chen

    Thursday, March 18, 2010 2:46 AM
  • Hello Chen,

    I can correctly run the code that Tj Tay gave in my Excel 2007, and as Tj suggested you could record a macro when you perfrom the same actions in Excel UI, then check out the code in VBE you'll get the correct answer.

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, March 19, 2010 8:58 AM
  • Thanks. I used Excel 2003. It can be the reason I think.

    Is it possible for that I wanna confirm the way for Excel 2003?


    Many Thanks & Best Regards, HuaMin Chen

    Friday, March 26, 2010 2:22 AM
  • Yes, I've just tested the code in Excel 2003 to ensure that it would work, and it actually works without any problem.

    Hope this helps.

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, March 26, 2010 5:18 AM
  • thanks. But I'm with the following error for these 2 ways.
    Range("I7:I7").Select
    Selection.Font.Color = 65433

    or

    Range("I7:I7").Font.ColorIndex = 3

    run-time error 1004: unable to set the colorindex property of the font class

    in Excel 2003


    Many Thanks & Best Regards, HuaMin Chen

    Friday, March 26, 2010 6:46 AM
  • is it a protected Workbook?

    I could run above code fine, may be you could try to create a new workbook and run the code again as test.

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, March 26, 2010 7:32 AM
  • Many many thanks. It's fine after I've unprotected the sheet. How about that I need to protect the sheet? Is there still one way for that?
    Many Thanks & Best Regards, HuaMin Chen
    Friday, March 26, 2010 8:01 AM
  • No, we could only achieve this by unprotect the Worksheet and then protect it again, the code should be like this:

    Activesheet.Unprotect, then, Activesheet.Protect, for more information about this two methods please refer to following:

    http://msdn.microsoft.com/en-us/library/bb214174.aspx
    http://msdn.microsoft.com/en-us/library/bb179210.aspx

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Jackson_1990 Friday, March 26, 2010 8:52 AM
    Friday, March 26, 2010 8:34 AM
  • Maybe you can use the "UserInterfaceOnly" parameter :

    ActiveSheet.Protect Password:="pw", UserInterfaceOnly:=True

    Regards.

    Daniel

    Friday, March 26, 2010 10:17 AM