Select sheet based on userform date input

M

mugitty

I have a workbook that is used for scheduling deliveries.

Sheet 1 is a "Control Panel" which among other things will pop up an
entry form for "New Deliveries".
Sheet 2 is set up as a list which receives the data from the userform.

This all works as desired presently, but I want to write the data from
the userform to a separate sheet by month based on the delivery date
entered on the form.

The form has a permanently visible calendar which when clicked writes
the selected date to a text box right below the calendar (as
mm/dd/yy).

How can I pull the month only from the text box and use it to determine
which of the monthly sheets will be activated for writing the data from
the form?
 
T

Tom Ogilvy

Dim mnth as String
mnth = Format(cdate(Textbox1.Text),"mmm")

Produces Mar for example. To get March, change mmm to mmmm

if you want a number between 1 and 12 inclusive

Dim mnth as Long
mnth = Format(cdate(Textbox1.Text),"m")
 
M

mugitty

Tom;

Thank you for your reply.

The code you posted looks like it would just change what was presented
in the text box?

I need the full date to appear in the final spreadsheet that is made
active based on the month of the scheduled delivery. Could I use your
code to return to another (hidden?) textbox while retaining the full
date for writing to the delivery schedule?

If so, how would I write the macro that actually selected the
appropriate month?

ex: If I enter 02/15/06 in the form, sheet "FEB" needs to be made
active and then all of the data from the form (including the full date)
needs to be written to the first empty row on that sheet.
 
T

Tom Ogilvy

No, my code answered your question.

Dim mnth as String
mnth = Format(cdate(Textbox1.Text),"mmm")
worksheets(mnth).Select
Range("B9").Value = Textbox1.Text


Using my code doesn't preclude you from doing whatever else you want with
the entry in the textbox. It doesn't affect the textbox value in any way.
 
M

mugitty

OK - Thanks again for your quick reply!

I'll give it a go as soon as the football games are over today.

(Have to wait, as I'm from Pittsburgh in the 70's and 80's and now live
in SE Washington state - so I'm watching closely to make sure that the
Steelers and the Seahawks end up in the Super Bowl)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top