PC Review


Reply
Thread Tools Rate Thread

User input macro for a date.

 
 
StargateFanFromWork
Guest
Posts: n/a
 
      4th May 2005
I found the autorun code for a macro to work on Excel 2000
startup, so I have that. But I was hoping to do something
other than a message box. What is needed is for the user
to input a start date into the macro that the macro would
then drop into the appropriate cell (in this case, B7).
The spreadhseet is then geared to dump dates in various
other cells based on that one initial date. Is there a
way to do this, pls?

(The Excel programming group seems to be down, otherwise
I'd ask there. That's an off occurrent, I've never seen
groups down before. <g>)

Thank you. D
 
Reply With Quote
 
 
 
 
JulieD
Guest
Posts: n/a
 
      4th May 2005
Hi StargateFan (long time no see)

you can use an inputbox e.g.
Range("B7") = InputBox("Enter date")

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"StargateFanFromWork" <(E-Mail Removed)> wrote in message
news:058501c550c3$30840390$(E-Mail Removed)...
>I found the autorun code for a macro to work on Excel 2000
> startup, so I have that. But I was hoping to do something
> other than a message box. What is needed is for the user
> to input a start date into the macro that the macro would
> then drop into the appropriate cell (in this case, B7).
> The spreadhseet is then geared to dump dates in various
> other cells based on that one initial date. Is there a
> way to do this, pls?
>
> (The Excel programming group seems to be down, otherwise
> I'd ask there. That's an off occurrent, I've never seen
> groups down before. <g>)
>
> Thank you. D



 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      4th May 2005
one way:

Put this in the ThisWorkbook Code module:

Private Sub Workbook_Open()
Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter start date:", _
Title:="Start Date", _
Default:=Format(Date, "dd mmm yyyy"), _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until IsDate(vResponse)
Range("B7").Value = CDate(vResponse)
End Sub



In article <058501c550c3$30840390$(E-Mail Removed)>,
"StargateFanFromWork" <(E-Mail Removed)> wrote:

> I found the autorun code for a macro to work on Excel 2000
> startup, so I have that. But I was hoping to do something
> other than a message box. What is needed is for the user
> to input a start date into the macro that the macro would
> then drop into the appropriate cell (in this case, B7).
> The spreadhseet is then geared to dump dates in various
> other cells based on that one initial date. Is there a
> way to do this, pls?
>
> (The Excel programming group seems to be down, otherwise
> I'd ask there. That's an off occurrent, I've never seen
> groups down before. <g>)
>
> Thank you. D

 
Reply With Quote
 
StargateFan
Guest
Posts: n/a
 
      5th May 2005
On Wed, 04 May 2005 10:59:55 -0600, JE McGimpsey
<(E-Mail Removed)> wrote:

>one way:
>
>Put this in the ThisWorkbook Code module:
>
> Private Sub Workbook_Open()
> Dim vResponse As Variant
> Do
> vResponse = Application.InputBox( _
> Prompt:="Enter start date:", _
> Title:="Start Date", _
> Default:=Format(Date, "dd mmm yyyy"), _
> Type:=2)
> If vResponse = False Then Exit Sub 'User cancelled
> Loop Until IsDate(vResponse)
> Range("B7").Value = CDate(vResponse)
> End Sub


This works marvellously, thank you! I just changed the macro name to
the autorun one so that that this macro pops up immediately upon
opening the workbook. This is great! The sole purpose of the
spreadsheet is to create a new time sheet for the employees for every
2 week pay period.

Actually, I just thought of something that would make this spreadsheet
perfect. Is there a way to get this user input into one more cell,
say A5? On testing the above situation, I realized that this is so
fantastic that if we could get another cell populated with the start
date, that that would mean that the user needs to only input _one_
items, the initial date called for!

The above start date goes at the top of the column that has each date.
Along the right-hand side people put their hours worked. But just
above B7 where these dates start, there is a box where they must write
in the start and end dates of that pay period. I just thought that if
I split this into 2 cells and have A5 receive the same data input as
B7, then the cell underneath I could easily code to automatically put
in the end date. These are always 2 weeks apart on a Wednesday.

Thanks so much! This is totally awesome. Though I always credit all
these nifty tricks to you all here in the Excel ngs, there's no
question that you all make me look very, very good! <lol>

>In article <058501c550c3$30840390$(E-Mail Removed)>,
> "StargateFanFromWork" <(E-Mail Removed)> wrote:
>
>> I found the autorun code for a macro to work on Excel 2000
>> startup, so I have that. But I was hoping to do something
>> other than a message box. What is needed is for the user
>> to input a start date into the macro that the macro would
>> then drop into the appropriate cell (in this case, B7).
>> The spreadhseet is then geared to dump dates in various
>> other cells based on that one initial date. Is there a
>> way to do this, pls?
>>
>> (The Excel programming group seems to be down, otherwise
>> I'd ask there. That's an off occurrent, I've never seen
>> groups down before. <g>)
>>
>> Thank you. D


 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      5th May 2005
One way would be to change the B7 in the macro to A5, then in B7 enter
the formula

=A5

However if you want both to be entered by macro, add this line

Range("A5").Value = CDate(vResponse)

right after

Range("B7").Value = CDate(vResponse)

FYI: Note that autorun macros, while they still work, have been
deprecated in favor of event macros. The Workbook_Open() event fires
whenever the workbook opens. That event is a workbook-level event, so it
has to live in the Workbook's ThisWorkbook code module rather than a
regular code module.



In article <(E-Mail Removed)>,
StargateFan <IDon'tAcceptSpam@IDon'tAcceptSpam.com> wrote:

> Actually, I just thought of something that would make this spreadsheet
> perfect. Is there a way to get this user input into one more cell,
> say A5?

 
Reply With Quote
 
StargateFanFromWork
Guest
Posts: n/a
 
      5th May 2005
You are _so_ right!! Trouble sometimes is that one wants
to make things more complicated than they are! When I
arrived at the office this morning and had the actual file
to work with I got one of those "d'uh" moments. All I did
was put the other 2 dates (start and end) dependent on
B7. Then I added IF syntax so that if B7 is empty, I
don't get a weird Jan.01.1900 date and the 2 cells remain
blank! <g>

This works like a charm! I know that once we distribute
this, everyone will save loads of time. I already did up
my time sheet for the next pay period and it was so easy!!

Thanks.

>-----Original Message-----
>One way would be to change the B7 in the macro to A5,

then in B7 enter
>the formula
>
> =A5
>
>However if you want both to be entered by macro, add this

line
>
> Range("A5").Value = CDate(vResponse)
>
>right after
>
> Range("B7").Value = CDate(vResponse)
>
>FYI: Note that autorun macros, while they still work,

have been
>deprecated in favor of event macros. The Workbook_Open()

event fires
>whenever the workbook opens. That event is a workbook-

level event, so it
>has to live in the Workbook's ThisWorkbook code module

rather than a
>regular code module.
>
>
>
>In article <(E-Mail Removed)>,
> StargateFan <IDon'tAcceptSpam@IDon'tAcceptSpam.com>

wrote:
>
>> Actually, I just thought of something that would make

this spreadsheet
>> perfect. Is there a way to get this user input into

one more cell,
>> say A5?

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I include a date input box in a macro? Project Mgr Microsoft Excel Misc 6 19th Jun 2008 05:52 PM
User input date to return query after date Bob Quintal Microsoft Access 7 9th Jul 2007 09:14 PM
Date Match Input Macro =?Utf-8?B?TW9oYW1lZA==?= Microsoft Excel Programming 0 19th Jan 2004 07:51 AM
Macro - Can a macro be stopped based on user input? Alison Microsoft Access Macros 1 18th Jul 2003 01:27 AM
Re: Macro - Can a macro be stopped based on user input? Ken Snell Microsoft Access Macros 0 16th Jul 2003 02:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:48 AM.