LoneReaper
08-23-2017, 11:36 PM
Hi all
I'm going back over some of my old code for a Word document I use for our orders for clients. I was looking for a way to shorten the below code possibly using some form of a loop. I've tried a few different ways but to no avail (my skill in VBA is still limited).
ALB1F is Company1 Contact1 First Name
ALB1L is Company1 Contact1 Last Name
ALB1E is Company1 Contact1 Email Address
Each Company has a range of contacts, from 1 to about 8 (i was going to have an upper limited of 10) and likewise there are about 10 companies to work with. Each company I have based on an acronym of the company, however I'm open to changing or generalising this to something like Company1 or similar.
Thanks in advance.
If ListBox4 = ALB Then
Me.ListBox3.Clear
With ListBox3
.AddItem ALB1F & " " & ALB1L
.AddItem ALB2F & " " & ALB2L
End With
ElseIf ListBox4 = AML Then
Me.ListBox3.Clear
With ListBox3
.AddItem AML1F & " " & AML1L
End With
ElseIf ListBox4 = CON Then
Me.ListBox3.Clear
With ListBox3
.AddItem CON1F & " " & CON1L
.AddItem CON2F & " " & CON2L
End With
End If
End Sub
I'm going back over some of my old code for a Word document I use for our orders for clients. I was looking for a way to shorten the below code possibly using some form of a loop. I've tried a few different ways but to no avail (my skill in VBA is still limited).
ALB1F is Company1 Contact1 First Name
ALB1L is Company1 Contact1 Last Name
ALB1E is Company1 Contact1 Email Address
Each Company has a range of contacts, from 1 to about 8 (i was going to have an upper limited of 10) and likewise there are about 10 companies to work with. Each company I have based on an acronym of the company, however I'm open to changing or generalising this to something like Company1 or similar.
Thanks in advance.
If ListBox4 = ALB Then
Me.ListBox3.Clear
With ListBox3
.AddItem ALB1F & " " & ALB1L
.AddItem ALB2F & " " & ALB2L
End With
ElseIf ListBox4 = AML Then
Me.ListBox3.Clear
With ListBox3
.AddItem AML1F & " " & AML1L
End With
ElseIf ListBox4 = CON Then
Me.ListBox3.Clear
With ListBox3
.AddItem CON1F & " " & CON1L
.AddItem CON2F & " " & CON2L
End With
End If
End Sub