View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
John Wilson John Wilson is offline
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.