Results 1 to 6 of 6

Change color of commandbuttons based in cell values

Threaded View

mmf Change color of... 08-16-2008, 10:22 PM
Simon Lloyd Your fault is because you... 08-17-2008, 04:42 AM
Tom Schreiner Hi MMF. Please provide... 08-17-2008, 09:39 AM
mmf Sorry for that, here I am... 08-18-2008, 08:00 AM
mmf Hi Simon I was trying this ... 08-19-2008, 12:22 PM
Tom Schreiner Sorry for the delay but I... 08-20-2008, 08:50 AM
  1. #1
    Forum Contributor
    Join Date
    06-15-2007
    Location
    Scotland
    Posts
    142

    Change color of commandbuttons based in cell values

    Hi
    I would like to change the color of a set of commands buttons based in a cell value Fail(red) Pass(green)

    I have a main sheet with all the commandbuttos (one for each Item) in the real sheet I have more than 3 items that is the reason I would like to create something like the followint code

    then for each Item I have a sheet and in each sheet has a validation cell to choose pass or fail.
    But I get an error every time that the main sheet is activate and call the IpdateItemStatus sub
    Any help?
    Many thanks

    Sub UpdateItemStatus()
       Dim Itemname(3) As String
       Dim i
       Dim ItemSheetName As String
       Dim ButtonName As CommandButton
    
        Itemname(1) = "A1"
        Itemname(2) = "A2"
        Itemname(3) = "A3"
        For i = 1 To 3
          SheetName = Itemname(i)
          With ButtonName
    'I get an error here run time erro 91 Object variable or With Block variable not set      
           .Caption = "btn_" + Itemname(1)
           End With
    
           If Sheets(ItemSheetName).Range("D5") = "Fail" Then
              Sheets(MainSheet).ButtonName.BackColor = &H8000000F 'Red Color
           Else
              Sheets(MainSheet).ButtonName.BackColor = &HFF00& 'Green color
           End If
    End sub
    Last edited by VBA Noob; 08-17-2008 at 03:08 AM.

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