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.


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

Thanks for the reply Harold.Sorry to say I can't get the code to work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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.




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Text box format VBA

That would be good.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for the reply Harold.Sorry to say I can't get the code to work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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.






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

Thanks for your input Tom. Sorry I didn't explain myself properly. What I
meant by " Should I have pasted it into an after update event?" was I have
tried it in the Private Sub TextBox27_AfterUpdate() event and it is not
working should I have put it in a different event?

Regards
gregork

"Tom Ogilvy" wrote in message
...
That would be good.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for the reply Harold.Sorry to say I can't get the code to work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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.








  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Text box format VBA

Private Sub TextBox27_AfterUpdate()
If LCase(Trim(TextBox27.Text)) = "fail" Then
TextBox27.BackColor = "&HC0C0FF"
Else
TextBox27.BackColor = "&HFFFFFF"
End If
End Sub


worked fine for me - although you have to have more than one control on the
form or there is no afterupdate.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for your input Tom. Sorry I didn't explain myself properly. What I
meant by " Should I have pasted it into an after update event?" was I

have
tried it in the Private Sub TextBox27_AfterUpdate() event and it is not
working should I have put it in a different event?

Regards
gregork

"Tom Ogilvy" wrote in message
...
That would be good.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for the reply Harold.Sorry to say I can't get the code to work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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.












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

gregork,

Yes, it should have been pasted into the AfterUpdate event.
Looking at the code that you were given, it should work too.

Personally, I tend to shy away from that "&HC0C0FF" stuff
whenever I can. "vbRed", "vbGreen", etc. is a lot easier to
understand. The ColorIndex 3, ColorIndex 4, etc. can usually
get me what I need and is still easier to understand.
For help on colors, take a look at this site:
http://www.mvps.org/dmcritchie/excel/colors.htm

If you still can't get this to work, post your code (and where
you have it) and someone will surely do their best to help you.

John


"gregork" wrote in message
...
Thanks for your input Tom. Sorry I didn't explain myself properly. What I
meant by " Should I have pasted it into an after update event?" was I

have
tried it in the Private Sub TextBox27_AfterUpdate() event and it is not
working should I have put it in a different event?

Regards
gregork

"Tom Ogilvy" wrote in message
...
That would be good.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for the reply Harold.Sorry to say I can't get the code to work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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.










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

"John Wilson" skrev i melding
...

Personally, I tend to shy away from that "&HC0C0FF" stuff
whenever I can.


Seemed like what the OP wanted. And for color it's very familiar for the
ones among us that writes HTML "by hand" in pad-like text editors. But I
guess we're a minority :-)

--
HTH. Best wishes Harald
Followup to newsgroup only please


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

Sorry gentlemen I still can't get the thing to work. Here's the code. The
private sub textbox1 after update code works perfectly. I must be missing
something obvious here???


Private Sub UserForm_Initialize()
Me.TextBox1.Value = Sheets("Blend Sheet").Range("ac7").Text
Me.TextBox27.Value = Sheets("Blend Sheet").Range("ac16").Text
End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub


Private Sub TextBox1_AfterUpdate()
If Val(TextBox1.Value) Worksheets("Blend Sheet").Range("V7").Value And _
Val(TextBox1.Value) < Worksheets("Blend Sheet").Range("V6").Value Then
TextBox1.BackColor = &HC0C0FF
Else
TextBox1.BackColor = vbWhite
End If
End Sub


Private Sub TextBox27_AfterUpdate()
If TextBox27.Text = "Fail" Then TextBox27.BackColor = vbRed
Else
TextBox27.BackColor = vbGreen
End If

End Sub


Many Thanks
gregork



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

Yes, it should have been pasted into the AfterUpdate event.
Looking at the code that you were given, it should work too.

Personally, I tend to shy away from that "&HC0C0FF" stuff
whenever I can. "vbRed", "vbGreen", etc. is a lot easier to
understand. The ColorIndex 3, ColorIndex 4, etc. can usually
get me what I need and is still easier to understand.
For help on colors, take a look at this site:
http://www.mvps.org/dmcritchie/excel/colors.htm

If you still can't get this to work, post your code (and where
you have it) and someone will surely do their best to help you.

John


"gregork" wrote in message
...
Thanks for your input Tom. Sorry I didn't explain myself properly. What

I
meant by " Should I have pasted it into an after update event?" was I

have
tried it in the Private Sub TextBox27_AfterUpdate() event and it is not
working should I have put it in a different event?

Regards
gregork

"Tom Ogilvy" wrote in message
...
That would be good.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for the reply Harold.Sorry to say I can't get the code to

work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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.












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

If TextBox27.Text = "Fail" Then
TextBox27.BackColor = vbRed
Else
TextBox27.BackColor = vbGreen
End If

Note the line breaks.
--
HTH. Best wishes Harald
Followup to newsgroup only please

"gregork" skrev i melding
...
Sorry gentlemen I still can't get the thing to work. Here's the code. The
private sub textbox1 after update code works perfectly. I must be missing
something obvious here???


Private Sub UserForm_Initialize()
Me.TextBox1.Value = Sheets("Blend Sheet").Range("ac7").Text
Me.TextBox27.Value = Sheets("Blend Sheet").Range("ac16").Text
End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub


Private Sub TextBox1_AfterUpdate()
If Val(TextBox1.Value) Worksheets("Blend Sheet").Range("V7").Value And _
Val(TextBox1.Value) < Worksheets("Blend Sheet").Range("V6").Value Then
TextBox1.BackColor = &HC0C0FF
Else
TextBox1.BackColor = vbWhite
End If
End Sub


Private Sub TextBox27_AfterUpdate()
If TextBox27.Text = "Fail" Then TextBox27.BackColor = vbRed
Else
TextBox27.BackColor = vbGreen
End If

End Sub


Many Thanks
gregork



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

Yes, it should have been pasted into the AfterUpdate event.
Looking at the code that you were given, it should work too.

Personally, I tend to shy away from that "&HC0C0FF" stuff
whenever I can. "vbRed", "vbGreen", etc. is a lot easier to
understand. The ColorIndex 3, ColorIndex 4, etc. can usually
get me what I need and is still easier to understand.
For help on colors, take a look at this site:
http://www.mvps.org/dmcritchie/excel/colors.htm

If you still can't get this to work, post your code (and where
you have it) and someone will surely do their best to help you.

John


"gregork" wrote in message
...
Thanks for your input Tom. Sorry I didn't explain myself properly.

What
I
meant by " Should I have pasted it into an after update event?" was I

have
tried it in the Private Sub TextBox27_AfterUpdate() event and it is

not
working should I have put it in a different event?

Regards
gregork

"Tom Ogilvy" wrote in message
...
That would be good.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for the reply Harold.Sorry to say I can't get the code to

work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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.














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

Hello Harald,
It still did not work. I transposed the code exactly how you sent it. Then I
messed around with the event and tried the code with this:" Private Sub
TextBox27_Change()" and blow me down it works.
Thank you all for your kind help.

Regards
gregork

"Harald Staff" wrote in message
...
If TextBox27.Text = "Fail" Then
TextBox27.BackColor = vbRed
Else
TextBox27.BackColor = vbGreen
End If

Note the line breaks.
--
HTH. Best wishes Harald
Followup to newsgroup only please

"gregork" skrev i melding
...
Sorry gentlemen I still can't get the thing to work. Here's the code.

The
private sub textbox1 after update code works perfectly. I must be

missing
something obvious here???


Private Sub UserForm_Initialize()
Me.TextBox1.Value = Sheets("Blend Sheet").Range("ac7").Text
Me.TextBox27.Value = Sheets("Blend Sheet").Range("ac16").Text
End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub


Private Sub TextBox1_AfterUpdate()
If Val(TextBox1.Value) Worksheets("Blend Sheet").Range("V7").Value And

_
Val(TextBox1.Value) < Worksheets("Blend Sheet").Range("V6").Value

Then
TextBox1.BackColor = &HC0C0FF
Else
TextBox1.BackColor = vbWhite
End If
End Sub


Private Sub TextBox27_AfterUpdate()
If TextBox27.Text = "Fail" Then TextBox27.BackColor = vbRed
Else
TextBox27.BackColor = vbGreen
End If

End Sub


Many Thanks
gregork



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

Yes, it should have been pasted into the AfterUpdate event.
Looking at the code that you were given, it should work too.

Personally, I tend to shy away from that "&HC0C0FF" stuff
whenever I can. "vbRed", "vbGreen", etc. is a lot easier to
understand. The ColorIndex 3, ColorIndex 4, etc. can usually
get me what I need and is still easier to understand.
For help on colors, take a look at this site:
http://www.mvps.org/dmcritchie/excel/colors.htm

If you still can't get this to work, post your code (and where
you have it) and someone will surely do their best to help you.

John


"gregork" wrote in message
...
Thanks for your input Tom. Sorry I didn't explain myself properly.

What
I
meant by " Should I have pasted it into an after update event?" was

I
have
tried it in the Private Sub TextBox27_AfterUpdate() event and it is

not
working should I have put it in a different event?

Regards
gregork

"Tom Ogilvy" wrote in message
...
That would be good.

--
Regards,
Tom Ogilvy

gregork wrote in message
...
Thanks for the reply Harold.Sorry to say I can't get the code to

work.
Should I have pasted it into an after update event?
Any suggestions appreciated.

Many thanks
gregork

"Harald Staff" wrote in message
...
"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 06:24 AM.

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"