Change textbox color to gray as long as value not changed by user

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
224
Office Version
  1. 365
Platform
  1. Windows
I want to show a value from the previous user form into the next one. The number should show up in gray. As soon as the use changes the gray value, I'd like it to change to black again. THe following does read the previous value but the value does not change color. I tried this with both IF and CASE, but that is not the reason it does not work, I think.

VBA Code:
'make defult text grey as long as not changed by user
Private Sub txtNew_OpsDays_SSD_Change()
    If txtNew_OpsDays_SSD.Value = txtExising_OpsDays_SSD.Value Then
        Me.txtNew_OpsDays_SSD.BackColor = RGB(124, 124, 124)
    Else
        Me.txtNew_OpsDays_SSD.BackColor = RGB(255, 255, 255)
    End If
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi,
see if this update to your code does what you want

VBA Code:
'make defult text grey as long as not changed by user
Private Sub txtNew_OpsDays_SSD_Change()
    With txtNew_OpsDays_SSD
        .BackColor = IIf(.Value = txtExising_OpsDays_SSD.Value, _
                         RGB(124, 124, 124), RGB(255, 255, 255))
    End With
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top