PC Review


Reply
Thread Tools Rate Thread

Date Format returned from Userform to Excel worksheet

 
 
Lily
Guest
Posts: n/a
 
      22nd Mar 2010
Hi,

I have a routine vb where I have a form (RXWfrmDate) with the date
(m/d/yyyy) for the user to pick a date for download to specific cell on the
worksheet.

Sub RXWDate()
Dim DateIN As Date
Application.ScreenUpdating = False
RXWfrmDATE.Show
If frmCANCEL = True Then Exit Sub
ActiveWorkbook.Unprotect
Sheets("Reactor Water").Select
ActiveSheet.Unprotect
Range("C3") = DateIN
Range("C3").Select
Selection.NumberFormat = "m/d/yyyy"
Exit Sub
Application.ScreenUpdating = True
End Sub

However, the date that shows on Range "C3") after user input is 01/00/1900.

What am I missing?

Appreciate any help.

Thanks.

Lily
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Mar 2010
Try changing this:

Range("C3").Select
Selection.NumberFormat = "m/d/yyyy"

To this:

Range("C3") = Format(Range("C3").Value, "m/d/yyyy" )



"Lily" <(E-Mail Removed)> wrote in message
news:C72D607D-B2CF-4D6B-B905-(E-Mail Removed)...
> Hi,
>
> I have a routine vb where I have a form (RXWfrmDate) with the date
> (m/d/yyyy) for the user to pick a date for download to specific cell on
> the
> worksheet.
>
> Sub RXWDate()
> Dim DateIN As Date
> Application.ScreenUpdating = False
> RXWfrmDATE.Show
> If frmCANCEL = True Then Exit Sub
> ActiveWorkbook.Unprotect
> Sheets("Reactor Water").Select
> ActiveSheet.Unprotect
> Range("C3") = DateIN
> Range("C3").Select
> Selection.NumberFormat = "m/d/yyyy"
> Exit Sub
> Application.ScreenUpdating = True
> End Sub
>
> However, the date that shows on Range "C3") after user input is
> 01/00/1900.
>
> What am I missing?
>
> Appreciate any help.
>
> Thanks.
>
> Lily



 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      22nd Mar 2010
Try replacing

Sheets("Reactor Water").Select
ActiveSheet.Unprotect
Range("C3") = DateIN
Range("C3").Select
Selection.NumberFormat = "m/d/yyyy"

with

With Sheets("Reactor Water")
.Unprotect
.Range("C3") = DateValue(datein)
.Range("C3").NumberFormat = "m/d/yyyy"
End With


--
Jacob


"Lily" wrote:

> Hi,
>
> I have a routine vb where I have a form (RXWfrmDate) with the date
> (m/d/yyyy) for the user to pick a date for download to specific cell on the
> worksheet.
>
> Sub RXWDate()
> Dim DateIN As Date
> Application.ScreenUpdating = False
> RXWfrmDATE.Show
> If frmCANCEL = True Then Exit Sub
> ActiveWorkbook.Unprotect
> Sheets("Reactor Water").Select
> ActiveSheet.Unprotect
> Range("C3") = DateIN
> Range("C3").Select
> Selection.NumberFormat = "m/d/yyyy"
> Exit Sub
> Application.ScreenUpdating = True
> End Sub
>
> However, the date that shows on Range "C3") after user input is 01/00/1900.
>
> What am I missing?
>
> Appreciate any help.
>
> Thanks.
>
> Lily

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd Mar 2010
I think the problem is one of variable scope. You have DateIN declared as a
Date inside your RXWDate subroutine, but I'm guessing this value is being
set in your UserForm and I further guessing that you have a DateIN variable
declared in the UserForm's code somewhere as well. If I am right, then the
problem is each of those declarations are local to the code procedure they
are in and, as such, know nothing about each other. Try this... remove the
DateIN declaration from both locations, add a Module to your project
(Insert/Module from the VB Editor menu bar) and put your declaration for
DateIN in the Module's code window (doing this will make the variable
visible to all code modules within your project). Now see if your code works
as you expect it to.

--
Rick (MVP - Excel)



"Lily" <(E-Mail Removed)> wrote in message
news:C72D607D-B2CF-4D6B-B905-(E-Mail Removed)...
> Hi,
>
> I have a routine vb where I have a form (RXWfrmDate) with the date
> (m/d/yyyy) for the user to pick a date for download to specific cell on
> the
> worksheet.
>
> Sub RXWDate()
> Dim DateIN As Date
> Application.ScreenUpdating = False
> RXWfrmDATE.Show
> If frmCANCEL = True Then Exit Sub
> ActiveWorkbook.Unprotect
> Sheets("Reactor Water").Select
> ActiveSheet.Unprotect
> Range("C3") = DateIN
> Range("C3").Select
> Selection.NumberFormat = "m/d/yyyy"
> Exit Sub
> Application.ScreenUpdating = True
> End Sub
>
> However, the date that shows on Range "C3") after user input is
> 01/00/1900.
>
> What am I missing?
>
> Appreciate any help.
>
> Thanks.
>
> Lily


 
Reply With Quote
 
Lily
Guest
Posts: n/a
 
      22nd Mar 2010
Thanks. I tried your suggestions. When I inputted 2/2/2002 I got
12/30/1899 on Range C3.

Lily

"JLGWhiz" wrote:

> Try changing this:
>
> Range("C3").Select
> Selection.NumberFormat = "m/d/yyyy"
>
> To this:
>
> Range("C3") = Format(Range("C3").Value, "m/d/yyyy" )
>
>
>
> "Lily" <(E-Mail Removed)> wrote in message
> news:C72D607D-B2CF-4D6B-B905-(E-Mail Removed)...
> > Hi,
> >
> > I have a routine vb where I have a form (RXWfrmDate) with the date
> > (m/d/yyyy) for the user to pick a date for download to specific cell on
> > the
> > worksheet.
> >
> > Sub RXWDate()
> > Dim DateIN As Date
> > Application.ScreenUpdating = False
> > RXWfrmDATE.Show
> > If frmCANCEL = True Then Exit Sub
> > ActiveWorkbook.Unprotect
> > Sheets("Reactor Water").Select
> > ActiveSheet.Unprotect
> > Range("C3") = DateIN
> > Range("C3").Select
> > Selection.NumberFormat = "m/d/yyyy"
> > Exit Sub
> > Application.ScreenUpdating = True
> > End Sub
> >
> > However, the date that shows on Range "C3") after user input is
> > 01/00/1900.
> >
> > What am I missing?
> >
> > Appreciate any help.
> >
> > Thanks.
> >
> > Lily

>
>
> .
>

 
Reply With Quote
 
Lily
Guest
Posts: n/a
 
      22nd Mar 2010
Thanks Jacob. I tried your suggestion and still got 1/0/1900 on Range C3.
Lily

"Jacob Skaria" wrote:

> Try replacing
>
> Sheets("Reactor Water").Select
> ActiveSheet.Unprotect
> Range("C3") = DateIN
> Range("C3").Select
> Selection.NumberFormat = "m/d/yyyy"
>
> with
>
> With Sheets("Reactor Water")
> .Unprotect
> .Range("C3") = DateValue(datein)
> .Range("C3").NumberFormat = "m/d/yyyy"
> End With
>
>
> --
> Jacob
>
>
> "Lily" wrote:
>
> > Hi,
> >
> > I have a routine vb where I have a form (RXWfrmDate) with the date
> > (m/d/yyyy) for the user to pick a date for download to specific cell on the
> > worksheet.
> >
> > Sub RXWDate()
> > Dim DateIN As Date
> > Application.ScreenUpdating = False
> > RXWfrmDATE.Show
> > If frmCANCEL = True Then Exit Sub
> > ActiveWorkbook.Unprotect
> > Sheets("Reactor Water").Select
> > ActiveSheet.Unprotect
> > Range("C3") = DateIN
> > Range("C3").Select
> > Selection.NumberFormat = "m/d/yyyy"
> > Exit Sub
> > Application.ScreenUpdating = True
> > End Sub
> >
> > However, the date that shows on Range "C3") after user input is 01/00/1900.
> >
> > What am I missing?
> >
> > Appreciate any help.
> >
> > Thanks.
> >
> > Lily

 
Reply With Quote
 
Lily
Guest
Posts: n/a
 
      22nd Mar 2010
Thanks Rick. Now I am getting frustrated.
You are correct I declared DateIN As Date in both places (Userform & Module
level). I deleted Dim DateIn As Date from both places. I added a Module
with Declaration Dim DateIN as Date.

No date was shown on Range C3 after inputting 2/2/2002.

Lily

"Rick Rothstein" wrote:

> I think the problem is one of variable scope. You have DateIN declared as a
> Date inside your RXWDate subroutine, but I'm guessing this value is being
> set in your UserForm and I further guessing that you have a DateIN variable
> declared in the UserForm's code somewhere as well. If I am right, then the
> problem is each of those declarations are local to the code procedure they
> are in and, as such, know nothing about each other. Try this... remove the
> DateIN declaration from both locations, add a Module to your project
> (Insert/Module from the VB Editor menu bar) and put your declaration for
> DateIN in the Module's code window (doing this will make the variable
> visible to all code modules within your project). Now see if your code works
> as you expect it to.
>
> --
> Rick (MVP - Excel)
>
>
>
> "Lily" <(E-Mail Removed)> wrote in message
> news:C72D607D-B2CF-4D6B-B905-(E-Mail Removed)...
> > Hi,
> >
> > I have a routine vb where I have a form (RXWfrmDate) with the date
> > (m/d/yyyy) for the user to pick a date for download to specific cell on
> > the
> > worksheet.
> >
> > Sub RXWDate()
> > Dim DateIN As Date
> > Application.ScreenUpdating = False
> > RXWfrmDATE.Show
> > If frmCANCEL = True Then Exit Sub
> > ActiveWorkbook.Unprotect
> > Sheets("Reactor Water").Select
> > ActiveSheet.Unprotect
> > Range("C3") = DateIN
> > Range("C3").Select
> > Selection.NumberFormat = "m/d/yyyy"
> > Exit Sub
> > Application.ScreenUpdating = True
> > End Sub
> >
> > However, the date that shows on Range "C3") after user input is
> > 01/00/1900.
> >
> > What am I missing?
> >
> > Appreciate any help.
> >
> > Thanks.
> >
> > Lily

>
> .
>

 
Reply With Quote
 
Lily
Guest
Posts: n/a
 
      22nd Mar 2010
Rick,

I did another check on the Declaration and it worked.

1. I made sure that the declarations for DateIN are deleted from the form &
the RXWDate Module.
2. I made sure that my Range C3 is Named As DateIN.
2. I made a Global Declaration of the DateIn As Date in my new Module.

Now I get the correct date/s I inputted on the form

Thanks Rick. Also thanks to all who sent suggestions.

Lily


"Rick Rothstein" wrote:

> I think the problem is one of variable scope. You have DateIN declared as a
> Date inside your RXWDate subroutine, but I'm guessing this value is being
> set in your UserForm and I further guessing that you have a DateIN variable
> declared in the UserForm's code somewhere as well. If I am right, then the
> problem is each of those declarations are local to the code procedure they
> are in and, as such, know nothing about each other. Try this... remove the
> DateIN declaration from both locations, add a Module to your project
> (Insert/Module from the VB Editor menu bar) and put your declaration for
> DateIN in the Module's code window (doing this will make the variable
> visible to all code modules within your project). Now see if your code works
> as you expect it to.
>
> --
> Rick (MVP - Excel)
>
>
>
> "Lily" <(E-Mail Removed)> wrote in message
> news:C72D607D-B2CF-4D6B-B905-(E-Mail Removed)...
> > Hi,
> >
> > I have a routine vb where I have a form (RXWfrmDate) with the date
> > (m/d/yyyy) for the user to pick a date for download to specific cell on
> > the
> > worksheet.
> >
> > Sub RXWDate()
> > Dim DateIN As Date
> > Application.ScreenUpdating = False
> > RXWfrmDATE.Show
> > If frmCANCEL = True Then Exit Sub
> > ActiveWorkbook.Unprotect
> > Sheets("Reactor Water").Select
> > ActiveSheet.Unprotect
> > Range("C3") = DateIN
> > Range("C3").Select
> > Selection.NumberFormat = "m/d/yyyy"
> > Exit Sub
> > Application.ScreenUpdating = True
> > End Sub
> >
> > However, the date that shows on Range "C3") after user input is
> > 01/00/1900.
> >
> > What am I missing?
> >
> > Appreciate any help.
> >
> > Thanks.
> >
> > Lily

>
> .
>

 
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
Date format changes in mail merge using Excel worksheet as data Curious Microsoft Excel Misc 2 6th Feb 2009 02:20 PM
DATE FORMAT CHANGE FROM EXCEL WORKSHEET TO PIVOT TABLE Wendy Microsoft Excel Misc 0 19th Nov 2008 12:54 AM
I need today's date returned as date format in formula =?Utf-8?B?Q01JQ29ubmll?= Microsoft Excel Misc 2 23rd Feb 2006 04:38 PM
Excel 2000 worksheet where I want to convert date format =?Utf-8?B?UnVzc2VsbC1zdGFuZWx5?= Microsoft Excel Misc 5 19th Dec 2005 02:02 AM
I am trying to format the date returned by a custom date property =?Utf-8?B?U2ltb24gQg==?= Microsoft Word Document Management 2 13th Aug 2005 11:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:16 PM.