Copy the value in the Inputbox

M

maywood

Hi,
I am using an InputBox to enter a date. This date should be copied into the
cell (4,7) in the format "mmm. yy". How to manage that.

Here is my code for the inputbox:

Private Sub CommandButton2_Click()
Dim d As Date
On Error GoTo err

Begin:
d = InputBox("Please enter a start date for the scenario!", _
"Start date")
If IsDate(d) And d >= "01.01.2008" Then
Else
MsgBox "No existing input data for this date!"

GoTo Begin
End If

Exit Sub

err:
MsgBox "Please only enter a valid date!"
GoTo Begin
End Sub
 
P

Patrick Molloy

don't confuse format with content. A cell can hold a date and be formatted so
that you see something else, such as MMM-YY or DDD

Option Explicit
Private Sub CommandButton2_Click()
Dim d As String
Do
d = InputBox("Please enter a start date for the scenario!", _
"Start date")
If IsDate(d) And d >= "01.01.2008" Then
Exit Do
Else
MsgBox "No existing input data for this date!"
Exit Sub
End If
Loop

Worksheets(">>>").Cells(4, 7).Value = Format$(d, "mmm.yy")

End Sub
 
G

Gary''s Student

Just format the cell first:

Sub TimeEntry()
Dim d As Date, s As String
s = Application.InputBox(prompt:="give me a date", Type:=2)
d = DateValue(s)
With Cells(4, 7)
.NumberFormat = "mmm. yy"
.Value = d
End With
End Sub
 
M

maywood

Works! Thanks allot!

Gary''s Student said:
Just format the cell first:

Sub TimeEntry()
Dim d As Date, s As String
s = Application.InputBox(prompt:="give me a date", Type:=2)
d = DateValue(s)
With Cells(4, 7)
.NumberFormat = "mmm. yy"
.Value = d
End With
End Sub
 

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