thefrasers
Board Regular
- Joined
- Aug 29, 2007
- Messages
- 58
Sometimes I feel that the untrained approach is disastrous. Just at the moment I've managed to do something which seems (fairly) advanced in VBA by building a user form which asks for inputs, copies those inputs onto the spreadsheet, and then works with them. However, I have come across two issues which I'm sure are incredibly simple but which I don't have a clue about because of my rather unstructured approach.
The first one relates to validation of inputs in the various text boxes and combo boxes. On the spreadsheet I can use data validation to generate error messages if (for instance) somebody puts in a letter when it should be a number. I can do this to some extent in VBA on a case-by-case basis, but would like some method of initial validation, particularly if somebody puts in a decimal rather than an integer.
The second one is I'm sure more trivial. To run my user form (called 'ticket') at the moment I have put one line of code at the end of another macro.
<code>
Sub OtherMacro()
... rest of code
Ticket.Show
End Sub
</code>
However, I cannot put this line of code on its own as a stand-alone macro (imaginatively called ticket) to simply load the form.
<code>
Sub Ticket()
Ticket.Show
End Sub
</code>
I get a compile error (whatever that is). This means that the spreadsheet has to run through the rest of the macro each time I want the form. Not a problem in this case but enormously irritating and probably highly inefficient. Does anyone know why this is?
Regards,
Peter
The first one relates to validation of inputs in the various text boxes and combo boxes. On the spreadsheet I can use data validation to generate error messages if (for instance) somebody puts in a letter when it should be a number. I can do this to some extent in VBA on a case-by-case basis, but would like some method of initial validation, particularly if somebody puts in a decimal rather than an integer.
The second one is I'm sure more trivial. To run my user form (called 'ticket') at the moment I have put one line of code at the end of another macro.
<code>
Sub OtherMacro()
... rest of code
Ticket.Show
End Sub
</code>
However, I cannot put this line of code on its own as a stand-alone macro (imaginatively called ticket) to simply load the form.
<code>
Sub Ticket()
Ticket.Show
End Sub
</code>
I get a compile error (whatever that is). This means that the spreadsheet has to run through the rest of the macro each time I want the form. Not a problem in this case but enormously irritating and probably highly inefficient. Does anyone know why this is?
Regards,
Peter