sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
I have the code below that conditionally formats the text boxes in a UserForm based on the data coming from the worksheet. Trying to figure out how to make use of this code to reset the formatting on the worksheet with the same formatting used in this code for the UserForm. I would think by looking at this most of the work is done, I just don't know how to reverse in order to set all of the formatting to match on the worksheet. Thanks, SS
VBA Code:
Private Sub UserForm_Activate()
Me.txtJobName.Locked = True ' set this property in Textbox Properties or with VBA like this
Me.txtJobName.Text = Sheets("Quick Search Job Status").Range("B3").Value
Dim wb As Workbook
Dim ws As Worksheet 'Added SPS,06/16/22
Dim tb As ListObject
Dim frm As Object 'UserForm
Dim job_name As String
Dim i As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Jobs") 'Added SPS,06/16/22, worksheet the table is on
Set tb = ws.ListObjects("G2JobList")
Set frm = Job_Status
With frm
Application.WindowState = xlMaximized
Job_Status.Height = Application.Height
'Job_Status.Width = Application.Width
job_name = Trim(.txtJobName.Text)
For i = 1 To tb.DataBodyRange.Rows.Count
If tb.ListColumns("Job Name").DataBodyRange.Cells(i).Value = job_name Then
Populate_Job_Status_Form
'COLOR LEGEND:
'Cell Color - Light Red = .BackColor = RGB(255, 199, 206)
'Font Color - Burgundy = .ForeColor = RGB(156, 0, 6)
'Cell Color - Light Yellow = .BackColor = RGB(255, 235, 156)
'Font Color - Dark Brown = .ForeColor = RGB(156, 87, 0)
'Cell Color - Light Green = .BackColor = RGB(198, 239, 206)
'Font Color - Dark Green = .ForeColor = RGB(0, 97, 0)
'Cell Color - Light Blue = .BackColor = RGB(184, 204, 228)
'Font Color - Dark Blue = .ForeColor = RGB(0, 0, 255)
'ENT
If tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtJobName.BackColor = RGB(255, 199, 206)
Me.txtJobName.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtJobName.BackColor = RGB(255, 235, 156)
Me.txtJobName.ForeColor = RGB(156, 87, 0)
End If
'ENT
If tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtENTREQDDate.BackColor = RGB(255, 199, 206)
Me.txtENTREQDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtENTREQDDate.BackColor = RGB(255, 235, 156)
Me.txtENTREQDDate.ForeColor = RGB(156, 87, 0)
End If
If tb.ListColumns("ENT" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <= tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("ENT" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtENTRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtENTRCVDDate.ForeColor = RGB(0, 97, 0)
End If
If tb.ListColumns("ENT" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value > tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("ENT" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtENTRCVDDate.BackColor = RGB(255, 199, 206)
Me.txtENTRCVDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("ENT" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value = "Complete" _
And tb.ListColumns("ENT" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtENTRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtENTRCVDDate.ForeColor = RGB(0, 97, 0)
End If
'FXTR
If tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtJobName.BackColor = RGB(255, 199, 206)
Me.txtJobName.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtJobName.BackColor = RGB(255, 235, 156)
Me.txtJobName.ForeColor = RGB(156, 87, 0)
End If
'FXTR
If tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtFXTRREQDDate.BackColor = RGB(255, 199, 206)
Me.txtFXTRREQDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtFXTRREQDDate.BackColor = RGB(255, 235, 156)
Me.txtFXTRREQDDate.ForeColor = RGB(156, 87, 0)
End If
If tb.ListColumns("FXTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <= tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("FXTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtFXTRRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtFXTRRCVDDate.ForeColor = RGB(0, 97, 0)
End If
If tb.ListColumns("FXTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value > tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("FXTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtFXTRRCVDDate.BackColor = RGB(255, 199, 206)
Me.txtFXTRRCVDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("FXTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value = "Complete" _
And tb.ListColumns("FXTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtFXTRRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtFXTRRCVDDate.ForeColor = RGB(0, 97, 0)
End If
'CONTR
If tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtJobName.BackColor = RGB(255, 199, 206)
Me.txtJobName.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtJobName.BackColor = RGB(255, 235, 156)
Me.txtJobName.ForeColor = RGB(156, 87, 0)
End If
'CONTR
If tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtCONTRREQDDate.BackColor = RGB(255, 199, 206)
Me.txtCONTRREQDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtCONTRREQDDate.BackColor = RGB(255, 235, 156)
Me.txtCONTRREQDDate.ForeColor = RGB(156, 87, 0)
End If
If tb.ListColumns("CONTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <= tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("CONTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtCONTRRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtCONTRRCVDDate.ForeColor = RGB(0, 97, 0)
End If
If tb.ListColumns("CONTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value > tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("CONTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtCONTRRCVDDate.BackColor = RGB(255, 199, 206)
Me.txtCONTRRCVDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("CONTR" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value = "Complete" _
And tb.ListColumns("CONTR" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtCONTRRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtCONTRRCVDDate.ForeColor = RGB(0, 97, 0)
End If
'Wiring
If tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtJobName.BackColor = RGB(255, 199, 206)
Me.txtJobName.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtJobName.BackColor = RGB(255, 235, 156)
Me.txtJobName.ForeColor = RGB(156, 87, 0)
End If
'Wiring
If tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date _
And tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtWiringREQDDate.BackColor = RGB(255, 199, 206)
Me.txtWiringREQDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value >= Date _
And tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value < Date + 30 Then
Me.txtWiringREQDDate.BackColor = RGB(255, 235, 156)
Me.txtWiringREQDDate.ForeColor = RGB(156, 87, 0)
End If
If tb.ListColumns("Wiring" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <= tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("Wiring" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtWiringRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtWiringRCVDDate.ForeColor = RGB(0, 97, 0)
End If
If tb.ListColumns("Wiring" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value > tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value _
And tb.ListColumns("Wiring" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtWiringRCVDDate.BackColor = RGB(255, 199, 206)
Me.txtWiringRCVDDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("Wiring" & Chr(10) & "REQD Date").DataBodyRange.Cells(i).Value = "Complete" _
And tb.ListColumns("Wiring" & Chr(10) & "RCVD Date").DataBodyRange.Cells(i).Value <> "" Then
Me.txtWiringRCVDDate.BackColor = RGB(198, 239, 206)
Me.txtWiringRCVDDate.ForeColor = RGB(0, 97, 0)
End If
'Job Status Last Update
If tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value <= Date _
And tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value > Date - 7 Then
Me.txtLastUpdateDate.BackColor = RGB(198, 239, 206)
Me.txtLastUpdateDate.ForeColor = RGB(0, 97, 0)
End If
If tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value <= Date - 7 _
And tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value > Date - 14 Then
Me.txtLastUpdateDate.BackColor = RGB(255, 235, 156)
Me.txtLastUpdateDate.ForeColor = RGB(156, 87, 0)
End If
If tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value <= Date - 14 _
And tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value > Date - 30 Then
Me.txtLastUpdateDate.BackColor = RGB(184, 204, 228)
Me.txtLastUpdateDate.ForeColor = RGB(0, 0, 255)
End If
If tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value <= Date - 30 Then
Me.txtLastUpdateDate.BackColor = RGB(255, 199, 206)
Me.txtLastUpdateDate.ForeColor = RGB(156, 0, 6)
End If
If tb.ListColumns("Job Status" & Chr(10) & "Last Update").DataBodyRange.Cells(i).Value = "" Then
Me.txtLastUpdateDate.BackColor = RGB(255, 199, 206)
Me.txtLastUpdateDate.ForeColor = RGB(156, 0, 6)
End If
Exit For
End If
Next
End With
NumLockCorrector
End Sub