Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Avoid multiple select constructs

Hi,
I m a newbie, I have this select case checking for textbox values. I
want to loop this so that it checks for all the textboxes. Or else I
got to write the same code for each Textbox :(

Select Case Me.TextBox1.Value

Case Is < 2
Me.TextBox1.BackColor = &H80FF80

Case 2 To 4
Me.TextBox1.BackColor = &H80FFFF

Case Is 4
Me.TextBox1.BackColor = &HFF
End Select
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Avoid multiple select constructs

For i = 1 To 10 'or whatver max value

Select Case Me.Controls("TextBox" & i).Value

Case Is < 2
Me.Controls("TextBox" & i).BackColor = &H80FF80

Case 2 To 4
Me.Controls("TextBox" & i).BackColor = &H80FFFF

Case Is 4
Me.Controls("TextBox" & i).BackColor = &HFF
End Select
Next i

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"azSuch" wrote in message
...
Hi,
I m a newbie, I have this select case checking for textbox values. I
want to loop this so that it checks for all the textboxes. Or else I
got to write the same code for each Textbox :(

Select Case Me.TextBox1.Value

Case Is < 2
Me.TextBox1.BackColor = &H80FF80

Case 2 To 4
Me.TextBox1.BackColor = &H80FFFF

Case Is 4
Me.TextBox1.BackColor = &HFF
End Select



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Avoid multiple select constructs

Assuming the controls are the first things on the form or in the container
then you could use something like this...

Dim N As Integer

For N = 0 To 2
With Me.Controls(N)
Select Case .Value

Case Is < 2
.BackColor = &H80FF80

Case 2 To 4
.BackColor = &H80FFFF

Case Is 4
.BackColor = &HFF

End Select
End With
Next N

....if they're not then you'll need to change the values in the loop (in the
with block) as you go to point to the correct controls.


"azSuch" wrote:

Hi,
I m a newbie, I have this select case checking for textbox values. I
want to loop this so that it checks for all the textboxes. Or else I
got to write the same code for each Textbox :(

Select Case Me.TextBox1.Value

Case Is < 2
Me.TextBox1.BackColor = &H80FF80

Case 2 To 4
Me.TextBox1.BackColor = &H80FFFF

Case Is 4
Me.TextBox1.BackColor = &HFF
End Select

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
How 2 avoid multiple IF's by LOOKUP's??? FARAZ QURESHI Excel Discussion (Misc queries) 3 June 8th 07 09:01 AM
How to avoid multiple IF's by LOOKUP's? FARAZ QURESHI Excel Discussion (Misc queries) 2 June 8th 07 05:15 AM
Asking for better logic to avoid multiple if's. [email protected] Excel Programming 1 January 17th 07 02:50 PM
avoid multiple text in range CG Rosén Excel Programming 0 November 24th 04 05:04 PM
If Select is the solution - how to avoid Select Stuart[_5_] Excel Programming 3 May 20th 04 09:57 PM


All times are GMT +1. The time now is 02:32 PM.

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

About Us

"It's about Microsoft Excel"