Problems with font color index

Skip Bisconer

Active Member
Joined
Jun 14, 2002
Messages
263
I am trying to make the font color red in a form text box when the value is less than 0. I thought I knew how to do it but it's not working. This is just a look up form based on a selection from a combo box. I have removed the conditional formating from the spread sheet cells involved to see if that makes a difference but it doesn't seem to. Here is my code for one of several textboxes. I appreciate any help you can give me.

With frmEarnings

.txtDividends = Range("EarningCompany").Cells(cmbCompany.ListIndex + 1, 2)
.txtDividends.Value = Format(Val(txtDividends), "$#,##0.00")
If .txtDividends < 0 Then
.txtDividends.Font.ColorIndex = 3
Else
'No change
End If
End With
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Skip

Since you are using a text box and formatting it as currency the if statement won't work.

Also it's the ForeColor property I think you want to change.

Try this.
Code:
 txtDividends = Range("EarningCompany").Cells(cmbCompany.ListIndex + 1, 2)
    If Val(txtDividends) < 0 Then
        txtDividends.ForeColor = &HFF&
    Else
        'No change
    End If
    txtDividends.Value = Format(Val(txtDividends), "$#,##0.00")
 
Upvote 0
Sorry to bother anyone. I found my own answer. I should have used fore color instead of font.colorindex

It's kind of like losing your wallet. You look for a couple of days then go down to the DMV stand in line for a half hour and pay your money to get a new license and whamo that night you will find the wallet.
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,561
Members
449,038
Latest member
Guest1337

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