Some user form questions

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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Managed to solve second problem by writing a sub called ticket_click and assigning it to a button. Why does this work?
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,887
Members
449,057
Latest member
Moo4247

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