+ Reply to Thread
Results 1 to 13 of 13

Command Buttons for Fill Colour and Font Colour

  1. #1
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Command Buttons for Fill Colour and Font Colour

    Hi all,

    I am really struggling trying to put a template together and would be very grateful for some help.

    Please see attachment.

    I want to use the four command buttons as follows:

    When a user selects any range (one or more cells) and then clicks a Fill Colour or Font Colour command button, I want all the rows for the selected range, from column A to column AC, to be highlighted accordingly – that is, fill colour or font colour. The command buttons must toggle – to (1) colour and (2) remove colour.

    Recalculate sheet only when there is a change in column X.

    Row 1 has the command buttons, and row 2 is the header row.

    Appreciate your help.

    Thank you.
    Gos-C
    Attached Files Attached Files
    Last edited by Gos-C; 09-22-2010 at 08:07 AM.
    Using Excel 2010 & Windows 10
    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Command Buttons for Fill Colour and Font Colour

    see this web page and modify the macros

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=416

  3. #3
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Command Buttons for Fill Colour and Font Colour

    gos-c
    I did a few experiments. see the file "change color gos.xls"

    I placed a command button from the CONTROL TOOLBAR in the cell D1
    i right clicked the button and clicked properties

    name: cmdfillcolor
    caption: fillcolor

    if your right click the sheet tab and click view code you can see this event code

    Please Login or Register  to view this content.
    remove design mode

    now select any one cell in each of two or three different rows(as you know if these are adjacent rows you can use "shift" key otherwise control key

    now click the button the rows will be colored with yellow
    again click the color will be removed.

    do this experiment(using command button as toggle button) two or three times.

    now you can modify this button code and also for different buttons you requrie

    does it work to your needs.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Command Buttons for Fill Colour and Font Colour

    Hi venkat1926,

    Thanks for your response.

    I would like only the range A:AC of the selection fill - instead of the entire row in the following lines:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Command Buttons for Fill Colour and Font Colour

    Can you help, anyone?

    Thanks,
    Gos-C

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Command Buttons for Fill Colour and Font Colour

    In Excel 2003, you can tear off the Fill Color menu so it sits on the sheet (click the dropdown, and when the toolbar appears, grab the top and drag it onto the sheet. Then you have single-click access to any fill color, or none.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Command Buttons for Fill Colour and Font Colour

    Hi Shg,

    I am (we are) using Excel 2007, but I posted the sample spreadsheet in Excel 2003 format in order to accommodate anyone who was not using Excel 2007. Furthermore, I need to use VBA to ensure that everyone who uses the template applies the exact colour because the colour would be used to sum/count in the data.

    I want to work with columns A to AC only - not the entire row,

    Thanks,
    Gos-C

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Command Buttons for Fill Colour and Font Colour

    You can use something like:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Command Buttons for Fill Colour and Font Colour

    because the colour would be used to sum/count in the data
    Although Excel 2007 allows for summing by color, I strongly advise against that technique. Color is not data (Mike Alexander). Use a helper column with hard and fast data instead.

    =if(condition,"Yellow","pink")

    or some such, and then use sumif or sumifs or a pivot table to sum up the data. This way you ensure that your data is version independent, portable and makes sense when printed out in black and white.

    Then use a simple sum

  10. #10
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Command Buttons for Fill Colour and Font Colour

    romperstomper, the code works on one row only - ever if more than one row is selected.

    teylyn, yes, I will be summing values in column X if the fill colour of the row is yellow.

    How can I have the code highlight all the rows in the selection?

    Thanks,
    Gos-C
    Last edited by Gos-C; 09-21-2010 at 12:11 PM.

  11. #11
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Command Buttons for Fill Colour and Font Colour

    I believe that I have figured it out:

    Please Login or Register  to view this content.
    Thanks for your help, everyone.

    Gos-C

  12. #12
    Registered User
    Join Date
    07-14-2011
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Command Buttons for Fill Colour and Font Colour

    Hi,

    I have a excel sheet and i need vba code to color 10 rows and 10 columns (each column with different color) on click of command button


    Can anyone help pls?

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Command Buttons for Fill Colour and Font Colour

    Hi, and welcome to the forum.

    Unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1