Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Command button color

Hello:

I have a userform with 15 command buttons on it. I want to make the color of
the command button the same color of the sheet tab. So I have the following
code:

MyColor = Sheet1.Tab.Color
Me.CommandButton1.BackColor = MyColor

However, since I have 15 buttons, I would like to write a code that will do
it to all command buttons without having to have to write for each command
button this code. It looks like there must be an easier way with either a
loop, or with...

Please help me.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Command button color

Give code something like this a try...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
C.BackColor = Worksheets(Counter).Tab.Color
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Hello:

I have a userform with 15 command buttons on it. I want to make the color
of
the command button the same color of the sheet tab. So I have the
following
code:

MyColor = Sheet1.Tab.Color
Me.CommandButton1.BackColor = MyColor

However, since I have 15 buttons, I would like to write a code that will
do
it to all command buttons without having to have to write for each command
button this code. It looks like there must be an easier way with either a
loop, or with...

Please help me.

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Command button color

Thanks. However, now all the sheets that don't have any color applied to
their tab the command button for that sheet is black. Do you know why? It
should be the default color. Can you please correct.

Thanks

"Rick Rothstein" wrote:

Give code something like this a try...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
C.BackColor = Worksheets(Counter).Tab.Color
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Hello:

I have a userform with 15 command buttons on it. I want to make the color
of
the command button the same color of the sheet tab. So I have the
following
code:

MyColor = Sheet1.Tab.Color
Me.CommandButton1.BackColor = MyColor

However, since I have 15 buttons, I would like to write a code that will
do
it to all command buttons without having to have to write for each command
button this code. It looks like there must be an easier way with either a
loop, or with...

Please help me.

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Command button color

Try this...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Thanks. However, now all the sheets that don't have any color applied to
their tab the command button for that sheet is black. Do you know why? It
should be the default color. Can you please correct.

Thanks

"Rick Rothstein" wrote:

Give code something like this a try...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
C.BackColor = Worksheets(Counter).Tab.Color
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Hello:

I have a userform with 15 command buttons on it. I want to make the
color
of
the command button the same color of the sheet tab. So I have the
following
code:

MyColor = Sheet1.Tab.Color
Me.CommandButton1.BackColor = MyColor

However, since I have 15 buttons, I would like to write a code that
will
do
it to all command buttons without having to have to write for each
command
button this code. It looks like there must be an easier way with either
a
loop, or with...

Please help me.

Thanks




  #5   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Command button color

thanks. I made a check box with your code. Now, the check box turns on the
color, how can I make that if the user uncheks the checkbox, the colors
should go back to the default?

Private Sub CheckBox1_Click()
If UserForm1.CheckBox1 = True Then
Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next
Else
End If
End Sub


"Rick Rothstein" wrote:

Try this...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Thanks. However, now all the sheets that don't have any color applied to
their tab the command button for that sheet is black. Do you know why? It
should be the default color. Can you please correct.

Thanks

"Rick Rothstein" wrote:

Give code something like this a try...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
C.BackColor = Worksheets(Counter).Tab.Color
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Hello:

I have a userform with 15 command buttons on it. I want to make the
color
of
the command button the same color of the sheet tab. So I have the
following
code:

MyColor = Sheet1.Tab.Color
Me.CommandButton1.BackColor = MyColor

However, since I have 15 buttons, I would like to write a code that
will
do
it to all command buttons without having to have to write for each
command
button this code. It looks like there must be an easier way with either
a
loop, or with...

Please help me.

Thanks






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Command button color

This should put it back to the default color.

c.BackColor = vbButtonFace

"art" wrote:

thanks. I made a check box with your code. Now, the check box turns on the
color, how can I make that if the user uncheks the checkbox, the colors
should go back to the default?

Private Sub CheckBox1_Click()
If UserForm1.CheckBox1 = True Then
Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next
Else
End If
End Sub


"Rick Rothstein" wrote:

Try this...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Thanks. However, now all the sheets that don't have any color applied to
their tab the command button for that sheet is black. Do you know why? It
should be the default color. Can you please correct.

Thanks

"Rick Rothstein" wrote:

Give code something like this a try...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
C.BackColor = Worksheets(Counter).Tab.Color
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Hello:

I have a userform with 15 command buttons on it. I want to make the
color
of
the command button the same color of the sheet tab. So I have the
following
code:

MyColor = Sheet1.Tab.Color
Me.CommandButton1.BackColor = MyColor

However, since I have 15 buttons, I would like to write a code that
will
do
it to all command buttons without having to have to write for each
command
button this code. It looks like there must be an easier way with either
a
loop, or with...

Please help me.

Thanks




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Command button color

This CheckBox Click event procedure should do what you want...

Private Sub CheckBox1_Click()
Dim C As Control
Dim Counter As Long
If CheckBox1.Value Then
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next
Else
For Each C In Me.Controls
If TypeOf C Is CommandButton Then C.BackColor = vbButtonFace
Next
End If
End Sub

--
Rick (MVP - Excel)


"art" wrote in message
...
thanks. I made a check box with your code. Now, the check box turns on the
color, how can I make that if the user uncheks the checkbox, the colors
should go back to the default?

Private Sub CheckBox1_Click()
If UserForm1.CheckBox1 = True Then
Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next
Else
End If
End Sub


"Rick Rothstein" wrote:

Try this...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
If Worksheets(Counter).Tab.Color Then
C.BackColor = Worksheets(Counter).Tab.Color
End If
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Thanks. However, now all the sheets that don't have any color applied
to
their tab the command button for that sheet is black. Do you know why?
It
should be the default color. Can you please correct.

Thanks

"Rick Rothstein" wrote:

Give code something like this a try...

Dim C As Control
Dim Counter As Long
For Each C In Me.Controls
If TypeOf C Is CommandButton Then
Counter = Counter + 1
C.BackColor = Worksheets(Counter).Tab.Color
End If
Next

--
Rick (MVP - Excel)


"art" wrote in message
...
Hello:

I have a userform with 15 command buttons on it. I want to make the
color
of
the command button the same color of the sheet tab. So I have the
following
code:

MyColor = Sheet1.Tab.Color
Me.CommandButton1.BackColor = MyColor

However, since I have 15 buttons, I would like to write a code that
will
do
it to all command buttons without having to have to write for each
command
button this code. It looks like there must be an easier way with
either
a
loop, or with...

Please help me.

Thanks





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change color of command button dhstein Excel Discussion (Misc queries) 1 May 21st 09 01:08 AM
Command Button Color Palette Greg in CO[_2_] Excel Programming 1 August 19th 08 06:51 PM
Excel Command Button Color justbrewit Excel Programming 5 August 15th 06 11:22 PM
Command Button Color For Next Loop John Wilson Excel Programming 3 September 15th 05 05:57 PM
command button color mark kubicki Excel Programming 1 August 13th 04 05:29 PM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"