+ Reply to Thread
Results 1 to 5 of 5

Need CommandButton to run macro and change cell color

  1. #1
    Registered User
    Join Date
    06-05-2015
    Location
    Illinois
    MS-Off Ver
    2010
    Posts
    12

    Need CommandButton to run macro and change cell color

    I have the following code that works fine within the given range. However, if a cell within the given range meets the criteria of the macro, how can I add code to change that cell's color to red?


    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("D5:D6,D10:D18")
    If rng > Range("D21") / 2 Then
    rng = Range("D21") / 2
    End If
    Next rng
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Need CommandButton to run macro and change cell color

    Hi taser241,

    The following will color a cell red:
    Please Login or Register  to view this content.

    To clear color from a cell:
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need CommandButton to run macro and change cell color

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-05-2015
    Location
    Illinois
    MS-Off Ver
    2010
    Posts
    12

    Re: Need CommandButton to run macro and change cell color

    Lewis and John,

    Thank you so much. Both worked great.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need CommandButton to run macro and change cell color

    You're welcome. Glad too help out and thanks for the feedback. Please mark this thread as SOLVED. See link for guidance.

    http://www.excelforum.com/forum-rule...rum-rules.html

+ 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. Macro to change cell text color based on darkness of cell fill color
    By cincyshirm61 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-25-2014, 12:11 PM
  2. VBA / Macro help needed to change the barchart color based on Cell Color
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2012, 09:15 AM
  3. Change Active CommandButton Color
    By zplugger in forum Excel General
    Replies: 3
    Last Post: 09-11-2012, 12:46 PM
  4. [SOLVED] Commandbutton color change
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-29-2011, 11:06 AM
  5. CommandButton color change on event
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-16-2005, 11:35 PM

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