Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Text box format VBA

Hi All,
Can you conditionally format a text box back colour on a user form? For
instance if the value in textbox1 was not in between (sheet1 cell= C1 and
sheet1 cell= C2) make the textbox1 back colour red.
How would you do this?

Regards
gregork


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Text box format VBA

gregork,

In the TextBox AfterUpdate Event.

Private Sub TextBox1_AfterUpdate()
If Val(TextBox1.Value) Worksheets("Sheet1").Range("C1").Value And _
Val(TextBox1.Value) < Worksheets("Sheet1").Range("C2").Value Then
TextBox1.BackColor = vbRed
Else
TextBox1.BackColor = vbWhite
End If
End Sub

John

"gregork" wrote in message
...
Hi All,
Can you conditionally format a text box back colour on a user form? For
instance if the value in textbox1 was not in between (sheet1 cell= C1 and
sheet1 cell= C2) make the textbox1 back colour red.
How would you do this?

Regards
gregork




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Text box format VBA

Perfect, many thanks John.

Kind Regards
gregork

"John Wilson" wrote in message
...
gregork,

In the TextBox AfterUpdate Event.

Private Sub TextBox1_AfterUpdate()
If Val(TextBox1.Value) Worksheets("Sheet1").Range("C1").Value And _
Val(TextBox1.Value) < Worksheets("Sheet1").Range("C2").Value Then
TextBox1.BackColor = vbRed
Else
TextBox1.BackColor = vbWhite
End If
End Sub

John

"gregork" wrote in message
...
Hi All,
Can you conditionally format a text box back colour on a user form? For
instance if the value in textbox1 was not in between (sheet1 cell= C1

and
sheet1 cell= C2) make the textbox1 back colour red.
How would you do this?

Regards
gregork






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Text box format VBA

gregork,

Happy to have been a help.
Thanks for the reply.

John

"gregork" wrote in message
...
Perfect, many thanks John.

Kind Regards
gregork

"John Wilson" wrote in message
...
gregork,

In the TextBox AfterUpdate Event.

Private Sub TextBox1_AfterUpdate()
If Val(TextBox1.Value) Worksheets("Sheet1").Range("C1").Value And _
Val(TextBox1.Value) < Worksheets("Sheet1").Range("C2").Value Then
TextBox1.BackColor = vbRed
Else
TextBox1.BackColor = vbWhite
End If
End Sub

John

"gregork" wrote in message
...
Hi All,
Can you conditionally format a text box back colour on a user form?

For
instance if the value in textbox1 was not in between (sheet1 cell= C1

and
sheet1 cell= C2) make the textbox1 back colour red.
How would you do this?

Regards
gregork








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Text box format VBA

John I hope your still out there. I'm having trouble with another formatting
problem. I want to format back colour based on text in a textbox. i.e. If
textbox27 text="fail" then
TextBox27.BackColor = &HC0C0FF. I've tried variations on the code you gave
me but I can't quite make it happen.

Kind Regards
gregork



"John Wilson" wrote in message
...
gregork,

Happy to have been a help.
Thanks for the reply.

John

"gregork" wrote in message
...
Perfect, many thanks John.

Kind Regards
gregork

"John Wilson" wrote in message
...
gregork,

In the TextBox AfterUpdate Event.

Private Sub TextBox1_AfterUpdate()
If Val(TextBox1.Value) Worksheets("Sheet1").Range("C1").Value And _
Val(TextBox1.Value) < Worksheets("Sheet1").Range("C2").Value Then
TextBox1.BackColor = vbRed
Else
TextBox1.BackColor = vbWhite
End If
End Sub

John

"gregork" wrote in message
...
Hi All,
Can you conditionally format a text box back colour on a user form?

For
instance if the value in textbox1 was not in between (sheet1 cell=

C1
and
sheet1 cell= C2) make the textbox1 back colour red.
How would you do this?

Regards
gregork












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Text box format VBA

"gregork" wrote in message
...
I want to format back colour based on text in a textbox. i.e. If
textbox27 text="fail" then
TextBox27.BackColor = &HC0C0FF.


You are very close:

If TextBox27.Text = "fail" Then
TextBox27.BackColor = "&HC0C0FF"
Else
TextBox27.BackColor = "&HFFFFFF"
End If

But consider uppercase, mixed case, part entries, trailing spaces...
If InStr(Trim$(LCase$(TextBox27.Text)), "fail") 0 Then
reacts also on entry " You FAILED madam"
--
HTH. Best wishes Harald
Followup to newsgroup only please.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
from date format convert to text format is wrong nooris Excel Discussion (Misc queries) 2 February 4th 10 03:41 PM
Need help with converting CUSTOM format/TEXT format to DATE format Deo Cleto Excel Worksheet Functions 6 June 2nd 09 08:14 PM
Change Date Format to Specific Text Format When Copying [email protected] Excel Discussion (Misc queries) 4 December 23rd 08 03:43 PM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM
how to format excel format to text format with separator "|" in s. azlan New Users to Excel 1 January 31st 05 12:57 PM


All times are GMT +1. The time now is 12:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"