ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For...Each loop problem (https://www.excelbanter.com/excel-programming/423443-each-loop-problem.html)

synapse5150

For...Each loop problem
 

I am trying to loop through all the listboxes I have in an Excel
worksheet (NOT userform), and I'm having problems. If this was a
userform, I would use a for each loop (like 'for each control in
userform.controls') but I'm not sure how to translate this collection to
a worksheet. Any ideas?


--
synapse5150
------------------------------------------------------------------------
synapse5150's Profile: http://www.thecodecage.com/forumz/member.php?userid=115
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=58770


Simon Lloyd[_1021_]

For...Each loop problem
 

synapse5150;214061 Wrote:
I am trying to loop through all the listboxes I have in an Excel
worksheet (NOT userform), and I'm having problems. If this was a
userform, I would use a for each loop (like 'for each control in
userform.controls') but I'm not sure how to translate this collection to
a worksheet. Any ideas?Which version of excel are you using?, the controls on a worksheet are

Activex Objects.
Perhaps attach a workbook so we can help you directly with that.
*Attatchments.
*
To upload a workbook, click reply then add your few words, scroll down
past the submit button and you will see the Manage Attatchments button,
this is where you get to add files for upload, if you have any trouble
please use this link or the one at the bottom of the
any page.


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=58770


synapse5150[_2_]

For...Each loop problem
 

Thanks, All - you pointed me in the right direction. Here's the solution
I came up with:

Sub Main_Clear_Selections()
Dim oleList As OLEObject
Dim intI As Integer

For Each oleList In shtMain.OLEObjects
If oleList.OLEType = 2 Then
For intI = 0 To
ActiveSheet.OLEObjects(oleList.Name).Object.ListCo unt

ActiveSheet.OLEObjects(oleList.Name).Object.Select ed(intI) = False

Next intI
End If
Next oleList

End Sub



Couldn't have done it without your help! Thanks again!


--
synapse5150
------------------------------------------------------------------------
synapse5150's Profile: http://www.thecodecage.com/forumz/member.php?userid=115
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=58770



All times are GMT +1. The time now is 05:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com