Quick reference to object vba

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
Basically I want to use an if statement to say

if img1.visible = true or img2.visible = true or img3.visible = true etc

and was wondering if as the only difference in the name of the image control is the number there was a quicker way than typing them all out for instance like:

if img1-20.visible = true
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
they're just images on a userform. Being referenced at the click event of a command button
 
Upvote 0
Then:
Code:
Dim n as long
for n = 1 to 20
   if me.controls("img" & n).visible then
    ' do whatever
    exit for
   End If
next n
 
Upvote 0
Thanks, that's exactly what I wanted to know how to do. Have added it to my VBA notes.
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

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