For each control Question

yabbadabba

New Member
Joined
Mar 26, 2011
Messages
20
Hi guys,
I have a userform with a multipage on it. On each multipage (3 of) there are several text boxes on each page. I have a code on page3 that will change the background colour if a criteria is met, however it also changes the background colour on the textboxes on the other pages.
Here is my code:

For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.TextBox Then
If ctrl.Value = "." Then ctrl.BackColor = RGB(255, 255, 255)
End If
Next ctrl

What i would like is that the textboxes on page3 of the multipage change colour only and not the text boxes on the other pages.
Any help would be appreciated. Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You could put the Multipage number in the Tag property of the control and test that.
 
Upvote 0
Every page of a multipage object is a separate container. You can iterate through all the controls on each page without touching the controls on any other page. Check out the "Pages" collection.
 
Upvote 0
Maybe...

Code:
[font=Verdana]    [color=darkblue]For[/color] [color=darkblue]Each[/color] Ctrl [color=darkblue]In[/color] Me.MultiPage1.Pages(2).Controls
        [color=darkblue]If[/color] TypeName(Ctrl) = "TextBox" [color=darkblue]Then[/color]
            [color=darkblue]If[/color] Ctrl.Value = "." [color=darkblue]Then[/color] Ctrl.BackColor = RGB(255, 255, 255)
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] Ctrl[/font]
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top