Frank Freese
asked on
Changing the color of a command button label
Experts,
In my primary spreadsheet I have a form commandf button named Recon5010 with a text labeled Recon. The color of the text label is black.
Here's my objective:
If the value 'Wgs Whse Wkr 5015.100'!L35<>0 (a different spreadsheet) I'd like to change the label color to red for Recon5010 from black, indicating I have a reconciliation problem in spreadsheet Wgs Whse Wkr 5015.100
In my primary spreadsheet I have a form commandf button named Recon5010 with a text labeled Recon. The color of the text label is black.
Here's my objective:
If the value 'Wgs Whse Wkr 5015.100'!L35<>0 (a different spreadsheet) I'd like to change the label color to red for Recon5010 from black, indicating I have a reconciliation problem in spreadsheet Wgs Whse Wkr 5015.100
Is that sheet in the same file?
You can either put a formula on the sheet with the button and use the sheet's Calculate event to colour the text, or use the calculate event of the other sheet.
You can either put a formula on the sheet with the button and use the sheet's Calculate event to colour the text, or use the calculate event of the other sheet.
Private Sub Worksheet_Calculate()
If Sheets("Wgs Whse Wkr 5015.100").range("L35").Value <> 0 Then
Me.Buttons("Button 2").Font.ColorIndex = 3
Else
Me.Buttons("Button 2").Font.ColorIndex = 1
end if
End Sub
Obviously replace Button 2 with Recon5010. :)
ASKER
I tried putting the above code in the with the sheets Calculate event as follows:
Private Sub Worksheet_Calculate()
If Sheets("Wgs Whse Wkr 5015.100").Range("L35").Va lue <> 0 Then
Me.Buttons("Recon5015100") .Font.Colo rIndex = 3
Else
Me.Buttons("Recon5015100") .Font.Colo rIndex = 1
End If
End Sub
And got an error and I think I know why. Me.Buttons("Recon5015100") exits on one spreadsheet and I'm trying to change the color on another spreadsheet called "Month Total". It looks like I would need to reference back to the "Month Total" spreadsheet but I don't know how to do that?
Also, since I have my code on the in the first spreadsheet ("Wgs Whse Wkr 5015.100") can I not change my If statement to something like this:
If L35<> 0 Then
.
.
.
.
End If
Private Sub Worksheet_Calculate()
If Sheets("Wgs Whse Wkr 5015.100").Range("L35").Va
Me.Buttons("Recon5015100")
Else
Me.Buttons("Recon5015100")
End If
End Sub
And got an error and I think I know why. Me.Buttons("Recon5015100")
Also, since I have my code on the in the first spreadsheet ("Wgs Whse Wkr 5015.100") can I not change my If statement to something like this:
If L35<> 0 Then
.
.
.
.
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried this but it failed:
Private Sub Worksheet_Calculate()
If Range("L35") <> 0 Then
Sheets("Month Total").Me.Buttons("Recon5 015100").F ont.ColorI ndex = 3
Else
Sheets("Month Total").Me.Buttons("Recon5 015100").F ont.ColorI ndex = 1
End If
End Sub
Private Sub Worksheet_Calculate()
If Range("L35") <> 0 Then
Sheets("Month Total").Me.Buttons("Recon5
Else
Sheets("Month Total").Me.Buttons("Recon5
End If
End Sub
ASKER
there you go - great job...perfect and thank you again
Open in new window