I have the following code to conditionally format two text boxes based on their cell values and to format the numbers in the Text Boxes in a specific format. When I go to print the sheet the conditional formatting in the text boxes remains but the number formatting that is set by the VBA is removed. Text box 1 prints as something like 102.35241526359854 and Text Box 2 prints like .145368549521. Any ideas why this is happening?
Private Sub TextBox1_Change()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o> </o>
If TextBox1.Text < 45 Then TextBox1.BackColor = RGB(165, 194, 106)<o></o>
If TextBox1.Text < 45 Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox1.Text >= 45 And TextBox1.Text < 120 Then TextBox1.BackColor = RGB(255, 255, 50)<o></o>
If TextBox1.Text >= 45 And TextBox1.Text < 120 Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox1.Text >= 120 Then TextBox1.BackColor = RGB(245, 70, 70)<o></o>
If TextBox1.Text >= 120 Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox1.Text = "-" Or TextBox1.Text = "" Then TextBox1.BackColor = RGB(128, 128, 128)<o></o>
If TextBox1.Text = "-" Or TextBox1.Text = "" Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
<o> </o>
TextBox1.Text = Format(val(TextBox1.Text), "0")<o></o>
<o> </o>
End Sub<o></o>
<o> </o>
<o> </o>
Private Sub TextBox2_Change()<o></o>
<o> </o>
Dim sTemp As String, val As Single, val2 As Single<o></o>
sTemp = TextBox2.Text<o></o>
If Not (InStr(1, sTemp, "%", vbTextCompare) < 1 _<o></o>
And IsNumeric(sTemp)) Then _<o></o>
Exit Sub '<<<<<<o></o>
<o> </o>
val = CSng(sTemp)<o></o>
val2 = IIf(val < 1, val, val / 100)<o></o>
TextBox2.Text = Format(val2, "0%")<o></o>
<o> </o>
If val2 < 0.04 Then TextBox2.BackColor = RGB(165, 194, 106)<o></o>
If val2 < 0.04 Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
If val2 >= 0.04 And val2 < 0.12 Then TextBox2.BackColor = RGB(255, 255, 50)<o></o>
If val2 >= 0.04 And val2 < 0.12 Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
If val2 >= 0.12 Then TextBox2.BackColor = RGB(245, 70, 70)<o></o>
If val2 >= 0.12 Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox2.Text = "-" Or TextBox2.Text = "" Then TextBox2.BackColor = RGB(128, 128, 128)<o></o>
If TextBox2.Text = "-" Or TextBox2.Text = "" Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
<o> </o>
End Sub<o></o>
Private Sub TextBox1_Change()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o> </o>
If TextBox1.Text < 45 Then TextBox1.BackColor = RGB(165, 194, 106)<o></o>
If TextBox1.Text < 45 Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox1.Text >= 45 And TextBox1.Text < 120 Then TextBox1.BackColor = RGB(255, 255, 50)<o></o>
If TextBox1.Text >= 45 And TextBox1.Text < 120 Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox1.Text >= 120 Then TextBox1.BackColor = RGB(245, 70, 70)<o></o>
If TextBox1.Text >= 120 Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox1.Text = "-" Or TextBox1.Text = "" Then TextBox1.BackColor = RGB(128, 128, 128)<o></o>
If TextBox1.Text = "-" Or TextBox1.Text = "" Then TextBox1.ForeColor = RGB(0, 0, 0)<o></o>
<o> </o>
TextBox1.Text = Format(val(TextBox1.Text), "0")<o></o>
<o> </o>
End Sub<o></o>
<o> </o>
<o> </o>
Private Sub TextBox2_Change()<o></o>
<o> </o>
Dim sTemp As String, val As Single, val2 As Single<o></o>
sTemp = TextBox2.Text<o></o>
If Not (InStr(1, sTemp, "%", vbTextCompare) < 1 _<o></o>
And IsNumeric(sTemp)) Then _<o></o>
Exit Sub '<<<<<<o></o>
<o> </o>
val = CSng(sTemp)<o></o>
val2 = IIf(val < 1, val, val / 100)<o></o>
TextBox2.Text = Format(val2, "0%")<o></o>
<o> </o>
If val2 < 0.04 Then TextBox2.BackColor = RGB(165, 194, 106)<o></o>
If val2 < 0.04 Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
If val2 >= 0.04 And val2 < 0.12 Then TextBox2.BackColor = RGB(255, 255, 50)<o></o>
If val2 >= 0.04 And val2 < 0.12 Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
If val2 >= 0.12 Then TextBox2.BackColor = RGB(245, 70, 70)<o></o>
If val2 >= 0.12 Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
If TextBox2.Text = "-" Or TextBox2.Text = "" Then TextBox2.BackColor = RGB(128, 128, 128)<o></o>
If TextBox2.Text = "-" Or TextBox2.Text = "" Then TextBox2.ForeColor = RGB(0, 0, 0)<o></o>
<o> </o>
End Sub<o></o>