PC Review


Reply
Thread Tools Rate Thread

Code is changing date format

 
 
=?Utf-8?B?Sm9jaw==?=
Guest
Posts: n/a
 
      6th Nov 2007
Hi
The following code converts any text which is input to uppercase regardless
of where it is input within the workbook:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error GoTo ErrHandler
Application.EnableEvents = False
For Each cell In Target
With cell
If Not .HasFormula Then
cell.Value = StrConv(cell.Value, vbUpperCase)
End If
End With
Next cell
ErrHandler:
Application.EnableEvents = True
End Sub

My problem is that it also converts the dates in column B from dd/mmm (UK
format) to dd/mmm (US format) when entered. IE today's date is put in column
B(automatically by code) as 06/Nov but it is changed immediately to 11/Jun.
Can column B be omited from the code above or is there another way around
this?
Thanks


--
Traa Dy Liooar

Jock
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RG9tVGhlUG9t?=
Guest
Posts: n/a
 
      6th Nov 2007
Hi Jock
I tried to replicate your problem but failed......
I am working in the UK - pasted oyu code into the workbook module
Code worked fine with text
Dates entered as 06.11.2007 entered and stayed the same
Only woerd thing is that I could not change the format of the date to
anything else - just did not happen (ie applying a custom dd mmmm yyyy to a
cell where a date had already been input had no effect on the default
dd.mm.yyyy format) - strange

"Jock" wrote:

> Hi
> The following code converts any text which is input to uppercase regardless
> of where it is input within the workbook:
>
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> On Error GoTo ErrHandler
> Application.EnableEvents = False
> For Each cell In Target
> With cell
> If Not .HasFormula Then
> cell.Value = StrConv(cell.Value, vbUpperCase)
> End If
> End With
> Next cell
> ErrHandler:
> Application.EnableEvents = True
> End Sub
>
> My problem is that it also converts the dates in column B from dd/mmm (UK
> format) to dd/mmm (US format) when entered. IE today's date is put in column
> B(automatically by code) as 06/Nov but it is changed immediately to 11/Jun.
> Can column B be omited from the code above or is there another way around
> this?
> Thanks
>
>
> --
> Traa Dy Liooar
>
> Jock

 
Reply With Quote
 
=?Utf-8?B?Sm9jaw==?=
Guest
Posts: n/a
 
      6th Nov 2007
Thanks Dom. Have got around it by using a Worksheet_Change sub instead.
Cheers
--
Traa Dy Liooar

Jock


"DomThePom" wrote:

> Hi Jock
> I tried to replicate your problem but failed......
> I am working in the UK - pasted oyu code into the workbook module
> Code worked fine with text
> Dates entered as 06.11.2007 entered and stayed the same
> Only woerd thing is that I could not change the format of the date to
> anything else - just did not happen (ie applying a custom dd mmmm yyyy to a
> cell where a date had already been input had no effect on the default
> dd.mm.yyyy format) - strange
>
> "Jock" wrote:
>
> > Hi
> > The following code converts any text which is input to uppercase regardless
> > of where it is input within the workbook:
> >
> > Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> > On Error GoTo ErrHandler
> > Application.EnableEvents = False
> > For Each cell In Target
> > With cell
> > If Not .HasFormula Then
> > cell.Value = StrConv(cell.Value, vbUpperCase)
> > End If
> > End With
> > Next cell
> > ErrHandler:
> > Application.EnableEvents = True
> > End Sub
> >
> > My problem is that it also converts the dates in column B from dd/mmm (UK
> > format) to dd/mmm (US format) when entered. IE today's date is put in column
> > B(automatically by code) as 06/Nov but it is changed immediately to 11/Jun.
> > Can column B be omited from the code above or is there another way around
> > this?
> > Thanks
> >
> >
> > --
> > Traa Dy Liooar
> >
> > Jock

 
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
Changing the date format on the date table in a chart spudsnruf Microsoft Excel Charting 2 3rd Sep 2009 07:08 PM
changing date formatted as general number into date format =?Utf-8?B?cGdoaW8=?= Microsoft Excel Programming 4 2nd Mar 2007 05:17 PM
Changing the date format & adding the date range to the header =?Utf-8?B?UHVyZUV2aWw=?= Microsoft Access 1 6th Oct 2006 11:31 PM
Re: Changing date serial numbers to date format Bob Umlas Microsoft Excel Discussion 0 14th Apr 2005 12:58 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


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