jeudi 25 juin 2015

VBA Excel Assigning an universal condition to textboxes

So I have a userform with a set of textboxes. In general I am taking their inputs and printing to a textfile.

User Screen:

UserScreen

Current Output:

output

So I have code that prints the three values in a line in a txt file. Box1.Value + Box2.Value + Box3.Value etc.

The issue is when the user DOESN'T enter anything. Based on how this text file is read either the correct code OR just something like spaces or null equivalent to the max length of the text box.

Current Code:

If Len(Box1.Value) < Box1.MaxLength Then
Box1.Value = Space(Box1.MaxLength)
End If

Desired Output:

goodoutput

Now what if I want this to work for ALL TEXT BOXES. If a bad entry (less than the desired length) or no entry - then all textboxes occupy their max length. This would really help standardize the userform and save a lot of lines of code. (currently have 15 different text boxes).

Is there something like this in VBA? Can I put all the textboxes in an array in VBA?

Aucun commentaire:

Enregistrer un commentaire