+ Reply to Thread
Results 1 to 3 of 3

Code cleanup

  1. #1
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Code cleanup

    I am using this code 30 times to "reset" 30 commandbuttons on a worksheet.
    There must be a more elegant way? Any assistance much appreciated

    Cheers,

    Peter (new to VBA)

    With ThisWorkbook.Sheets("Benefits").CommandButton1
    If Range("a100").Value <> "" Then
    .BackColor = &HFFC0C0
    Else
    .BackColor = &HE0E0E0
    End If
    End With

  2. #2
    Tim Williams
    Guest

    Re: Code cleanup


    With ThisWorkbook.Sheets("Benefits")

    SetButton .CommandButton1, .range("A100")
    SetButton .CommandButton2, .range("A101")
    '...etc
    end with

    Sub SetButton(cb as object, rng as range)
    if rng.value<>"" then
    cb.BackColor = &HFFC0C0
    else
    cb.BackColor = &HE0E0E0
    end if
    end sub


    Tim




    --
    Tim Williams
    Palo Alto, CA


    "peter.thompson"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > I am using this code 30 times to "reset" 30 commandbuttons on a
    > worksheet.
    > There must be a more elegant way? Any assistance much appreciated
    >
    > Cheers,
    >
    > Peter (new to VBA)
    >
    > With ThisWorkbook.Sheets("Benefits").CommandButton1
    > If Range("a100").Value <> "" Then
    > BackColor = &HFFC0C0
    > Else
    > BackColor = &HE0E0E0
    > End If
    > End With
    >
    >
    > --
    > peter.thompson
    > ------------------------------------------------------------------------
    > peter.thompson's Profile:

    http://www.excelforum.com/member.php...o&userid=29686
    > View this thread: http://www.excelforum.com/showthread...hreadid=502302
    >




  3. #3
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Thanks Tim

    Cheers

    Peter

+ 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