VBA: if textbox value is less than %, change back color

Xlacs

Board Regular
Joined
Mar 31, 2021
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hello Everyone,

I have this problem on my code.
basically, I wanted to change a textbox color if that value of a particular textbox is less than 95%.

But i'm having no luck. My guess is, this has something to do with the textbox converting to Numbers or percentage.

Any idea why? Haay..

Thanks In Advance guys.

Below is my code.

VBA Code:
Private Sub ComboBox1_Change()

Dim i As Long, LastRow As Long, ws As Worksheet
Set ws = Sheets("Sheet2")
LastRow = ws.Range("B" & Rows.Count).End(xlUp).Row

For i = 2 To LastRow

If Me.ComboBox1.Value = ws.Cells(i, "B") Then

Me.txt2 = ws.Cells(i, "B").Value
Me.txt3 = ws.Cells(i, "C").Value
Me.txt4 = ws.Cells(i, "D").Value
Me.txt5 = ws.Cells(i, "E").Value
Me.txt6 = Format(ws.Cells(i, "F").Value, "0.00%")
Me.txt7 = ws.Cells(i, "G").Value
Me.txt8 = ws.Cells(i, "H").Value

Me.txt9 = Format(ws.Cells(i, "I").Value, "0.00")

End If

Next i

If Me.ComboBox1.Value = "" Then

Me.txt2 = ""
Me.txt3 = ""
Me.txt4 = ""
Me.txt5 = ""
Me.txt6 = ""
Me.txt7 = ""
Me.txt8 = ""
Me.txt9 = ""

End If

If CDbl(txt6.Value) < 95 Then
txt6.BackColor = vbRed
Else
txt6.BackColor = vbGreen

End If

If txt9.Value < 3 Then
txt6.BackColor = vbRed
Else
txt9.BackColor = vbGreen

End If

End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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