Hi, I am a beginner to VBA looking for some help with a For Loop
I have a Userform with 18 Comboboxes named mid1, mid2, mid3 etc which would hold an item description and then 18 textboxes named mia1, mia2, mia3 etc which would hold corresponding currency amount (There are other textboxes on the userform as well)
On Userform Activate, I am trying to disable a mia textbox if the corresponding mid combobox is empty.
eg if mid3 is empty then mia3 needs to be Disabled.
This is what I have got so far:
I keep getting a compile error when i is set to 1, where am I going wrong.![]()
Private Sub UserForm_Activate() Dim coll As New Collection Dim item As TextBox Dim i As Integer coll.Add Me.mia1 coll.Add Me.mia2 coll.Add Me.mia3 coll.Add Me.mia4 coll.Add Me.mia5 coll.Add Me.mia6 coll.Add Me.mia7 coll.Add Me.mia8 coll.Add Me.mia9 coll.Add Me.mia10 coll.Add Me.mia11 coll.Add Me.mia12 coll.Add Me.mia13 coll.Add Me.mia14 coll.Add Me.mia15 coll.Add Me.mia16 coll.Add Me.mia17 coll.Add Me.mia18 Set i = 1 With i For Each item In coll If Me.Controls("mid" & i).text = "" Then item.Enabled = False item.BackColor = vbGrey i = i + 1 Next item End With End Sub
Also is a for loop the best way to achieve this?
Many thanks for all help.











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks