Code cleanup

P

peter.thompson

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
 
T

Tim Williams

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top