Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default How to enter dates in Excel cells using InputBox

Hello,

I have a worksheet, which must remain protected out of the two cells where
the user has to enter two dates, with 5 sheets containing prices I compare
using a StartDate and a End Date.

There should be a button €śCompare€ť
- starting a macro which opens a InputBox
- for the input of StartDate in the form as 25/05/1997
- and EndDate in the form as 25/09/1997,
- putting the dates respectively in the cells G3 and G4 of the sheet €śRates1€ť

Should the date be written in wrong way a MsgBox should show the message
"Please use the form DD/MM/1997" (the year must be always this!!!)

I use follwing listing:
Sub InserimentoPeriodo()
Dim DataInizio As Date
Dim DataFine As Date

DataInizio = InputBox("Inserisci la data di INIZIO periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "1-mag-1997")

If Year(DataInizio) < 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E1").Value = DataInizio

DataFine = InputBox("Inserisci la data di FINE periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "10-set-1997")
If Year(DataFine) < 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E2").Value = DataFine

End Sub

But.... it does not work if the user opens the wrong sheet and I am not able
to put a button in the sheet to let the macro working.

Thank you for helping

--
dilettante
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default How to enter dates in Excel cells using InputBox


"dilettante" schreef in
bericht ...
Hello,

I have a worksheet, which must remain protected out of the two cells where
the user has to enter two dates, with 5 sheets containing prices I compare
using a StartDate and a End Date.

There should be a button "Compare"
- starting a macro which opens a InputBox
- for the input of StartDate in the form as 25/05/1997
- and EndDate in the form as 25/09/1997,
- putting the dates respectively in the cells G3 and G4 of the sheet
"Rates1"

Should the date be written in wrong way a MsgBox should show the message
"Please use the form DD/MM/1997" (the year must be always this!!!)

I use follwing listing:


Sub InserimentoPeriodo()
Dim DataInizio As Date
Dim DataFine As Date

'E adesso:
If ActiveSheet.Name < "Rates1" Then Worksheets("Rates1").Activate



DataInizio = InputBox("Inserisci la data di INIZIO periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "1-mag-1997")

If Year(DataInizio) < 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E1").Value = DataInizio

DataFine = InputBox("Inserisci la data di FINE periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "10-set-1997")
If Year(DataFine) < 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E2").Value = DataFine

End Sub

But.... it does not work if the user opens the wrong sheet and I am not
able
to put a button in the sheet to let the macro working.

Thank you for helping

--
dilettante



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default How to enter dates in Excel cells using InputBox

Grazie
--
dilettante


"dilettante" wrote:

Hello,

I have a worksheet, which must remain protected out of the two cells where
the user has to enter two dates, with 5 sheets containing prices I compare
using a StartDate and a End Date.

There should be a button €śCompare€ť
- starting a macro which opens a InputBox
- for the input of StartDate in the form as 25/05/1997
- and EndDate in the form as 25/09/1997,
- putting the dates respectively in the cells G3 and G4 of the sheet €śRates1€ť

Should the date be written in wrong way a MsgBox should show the message
"Please use the form DD/MM/1997" (the year must be always this!!!)

I use follwing listing:
Sub InserimentoPeriodo()
Dim DataInizio As Date
Dim DataFine As Date

DataInizio = InputBox("Inserisci la data di INIZIO periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "1-mag-1997")

If Year(DataInizio) < 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E1").Value = DataInizio

DataFine = InputBox("Inserisci la data di FINE periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "10-set-1997")
If Year(DataFine) < 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E2").Value = DataFine

End Sub

But.... it does not work if the user opens the wrong sheet and I am not able
to put a button in the sheet to let the macro working.

Thank you for helping

--
dilettante

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using InpubBox to enter dates in two Excel cells dilettante Excel Programming 1 October 1st 06 04:38 PM
Inputbox to enter a % StephanieH Excel Programming 3 April 10th 06 04:00 PM
InputBox requesting dates between two predefined dates Barb Reinhardt Excel Programming 2 January 20th 06 09:45 PM
Entering dates in vba inputbox as ddmmyy. Excel returns mmddyy pkeegs Excel Programming 3 August 30th 05 08:57 AM
Inputbox to enter date Tom Ogilvy Excel Programming 0 July 27th 04 05:44 PM


All times are GMT +1. The time now is 10:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"