+ Reply to Thread
Results 1 to 7 of 7

click on a color button and after button click it will color entire row of cell you click

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    click on a color button and after button click it will color entire row of cell you click

    Can anyone direct me on what code I can put behind a button so that once I click on that button,

    What ever cell i click on, the whole row of that cell will be colored a certain color.

    Is this where i would used a target approach?

  2. #2
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: click on a color button and after button click it will color entire row of cell you cl

    It can be done by selecting cell first and than click the button

    Sub Button1_click()
        ActiveSheet.Rows(ActiveCell.Row).Interior.Color = RGB(255, 0, 0)
    End Sub

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,694

    Re: click on a color button and after button click it will color entire row of cell you cl

    try this:

    Sub cmd()
    ActiveCell.EntireRow.Interior.ColorIndex = 3
    End Sub
    See here for list of colorindex

    http://www.databison.com/excel-color...nge-using-vba/
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: click on a color button and after button click it will color entire row of cell you cl

    what if i want to do just certain set of continuous columns for example A-J

    How would I write the code to specify that target range?

  5. #5
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: click on a color button and after button click it will color entire row of cell you cl

    Try this.. this code will work without a button.. put the code in the sheet module..
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
       Dim Low As Double
       Dim High As Double
       Low = 26     '< change as desired
       High = 47   '< change as desired
    
       'If the target cell is clear
       If Target.EntireRow.Interior.ColorIndex = xlNone Then
    
          'Then change the background to a random color
          Target.EntireRow.Interior.ColorIndex = Int((High - Low + 1) * Rnd() + Low)
    
          'But if the target cell is already the color
       ElseIf Target.EntireRow.Interior.ColorIndex <> xlNone Then
    
          'Then clear the background color
          Target.EntireRow.Interior.ColorIndex = xlNone
    
       End If
    
    End Sub

  6. #6
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: click on a color button and after button click it will color entire row of cell you cl

    Sweeet thanks guys

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,694

    Re: click on a color button and after button click it will color entire row of cell you cl

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2012, 09:05 PM
  2. Excel 2007 : Change color of cell on click
    By TToc2u in forum Excel General
    Replies: 0
    Last Post: 12-08-2011, 07:04 PM
  3. Change cell color on click
    By oxicottin in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 01-03-2010, 02:23 AM
  4. Hold click - color of a cell changes
    By hege11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-10-2007, 06:34 AM
  5. [SOLVED] Change Color in Cell on Click
    By Ange Kappas in forum Excel General
    Replies: 1
    Last Post: 03-07-2006, 06:55 AM

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