End a with Statement with for multiple objects

scottyp10

New Member
Joined
Jul 22, 2017
Messages
2
I'm wondering how to avoid having to type out 'End With' after each with statement. Can anyone help?

Here's my code below:

Private Sub UserForm_Initialize()
'Start Userform Centered inside Excel Screen (for dual monitors)
Me.StartUpPosition = 0
Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)

'Declares the value in the date box
DateD.Value = Format(Date, "dd/mm/yyyy")

'With Statements declare the values in each of the list boxes
With TrainingType
.additem ""

With Trainer
.additem ""

With Team
.additem ""

With Stream
.additem ""

With Trainer
.additem ""

End With
End With
End With
End With
End With


End Sub
 
for each With you must close it End With, or you need to quantify the initial completely as Trainer.additem ""
 
Last edited:
Upvote 0
i understand why i have to type the with end etc. But how can i avoid having to type 'With End' 20 times for 20 list boxes? How would i quantify that at the top and also quantify the .additem if thats possible?

thanks for the reply
 
Upvote 0
Easy - don't use With!
Code:
TrainingType.additem ""
Trainer.additem ""
Team.additem ""
Stream.additem ""
Trainer.additem ""
 
Last edited:
Upvote 0
i understand why i have to type the with end etc. But how can i avoid having to type 'With End' 20 times for 20 list boxes? How would i quantify that at the top and also quantify the .additem if thats possible?

thanks for the reply

as i said above or ruddles has replied below
 
Upvote 0

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