Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Qn: How to show a date and time with a ' in it???

Hello Everyone,

I am trying to setup a page so that I can import a excel file to my
Microsoft Outlook Calendar. I can do it manually, but I am trying to write
a routine that will format the page for me. The problem is the time and
date. I have a routine that Tom Olgivy wrote for me:

Dim cell As Range
For Each cell In Range("A1:F10")
cell.Value = "'" & cell.Value
Next

It works for everything except the date and time. The problem is, when it
see's the time with a ', it treats it as TEXT. Now, if I manually put in a
' before the time in the formula bar, it will take it??? Then the time can
be imported correctly. But, how can I input that little tick ' in a routine
to do it automatically without it recognizing it as text???

Thanks.. mv


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default How to show a date and time with a ' in it???

Michael,

You need to use a custom function to check for time values - see the code
below.

HTH,
Bernie
MS Excel MVP

Sub TryNow()
Dim myCell As Range
For Each myCell In Range("A1:F10")
If IsTime(myCell) Or IsDate(myCell) Then
myCell.Value = "'" & myCell.Text
Else
myCell.Value = "'" & myCell.Value
End If
Next
End Sub

Public Function IsTime(myCell As Range) As Boolean
IsTime = True
With myCell
IsTime = IsTime And IsNumeric(.Value) And _
InStr(.NumberFormat, "h:m")
End With
End Function


"Michael Vaughan" wrote in message
...
Hello Everyone,

I am trying to setup a page so that I can import a excel file to my
Microsoft Outlook Calendar. I can do it manually, but I am trying to

write
a routine that will format the page for me. The problem is the time and
date. I have a routine that Tom Olgivy wrote for me:

Dim cell As Range
For Each cell In Range("A1:F10")
cell.Value = "'" & cell.Value
Next

It works for everything except the date and time. The problem is, when it
see's the time with a ', it treats it as TEXT. Now, if I manually put in

a
' before the time in the formula bar, it will take it??? Then the time

can
be imported correctly. But, how can I input that little tick ' in a

routine
to do it automatically without it recognizing it as text???

Thanks.. mv




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default How to show a date and time with a ' in it???

I did a bad job of trimming J.E. McGimpsey's code to handle only one cell
rather than a multi-area range. It should be:

Public Function IsTime(myCell As Range) As Boolean
With myCell
IsTime = IsNumeric(.Value) And _
InStr(.NumberFormat, "h:m")
End With
End Function

HTH,
Bernie
MS Excel MVP

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Michael,

You need to use a custom function to check for time values - see the code
below.

HTH,
Bernie
MS Excel MVP

Sub TryNow()
Dim myCell As Range
For Each myCell In Range("A1:F10")
If IsTime(myCell) Or IsDate(myCell) Then
myCell.Value = "'" & myCell.Text
Else
myCell.Value = "'" & myCell.Value
End If
Next
End Sub

Public Function IsTime(myCell As Range) As Boolean
IsTime = True
With myCell
IsTime = IsTime And IsNumeric(.Value) And _
InStr(.NumberFormat, "h:m")
End With
End Function


"Michael Vaughan" wrote in message
...
Hello Everyone,

I am trying to setup a page so that I can import a excel file to my
Microsoft Outlook Calendar. I can do it manually, but I am trying to

write
a routine that will format the page for me. The problem is the time and
date. I have a routine that Tom Olgivy wrote for me:

Dim cell As Range
For Each cell In Range("A1:F10")
cell.Value = "'" & cell.Value
Next

It works for everything except the date and time. The problem is, when

it
see's the time with a ', it treats it as TEXT. Now, if I manually put

in
a
' before the time in the formula bar, it will take it??? Then the time

can
be imported correctly. But, how can I input that little tick ' in a

routine
to do it automatically without it recognizing it as text???

Thanks.. mv






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to show a date and time with a ' in it???

Couldn't wait?

--
Regards,
Tom Ogilvy

"Michael Vaughan" wrote in message
...
Hello Everyone,

I am trying to setup a page so that I can import a excel file to my
Microsoft Outlook Calendar. I can do it manually, but I am trying to

write
a routine that will format the page for me. The problem is the time and
date. I have a routine that Tom Olgivy wrote for me:

Dim cell As Range
For Each cell In Range("A1:F10")
cell.Value = "'" & cell.Value
Next

It works for everything except the date and time. The problem is, when it
see's the time with a ', it treats it as TEXT. Now, if I manually put in

a
' before the time in the formula bar, it will take it??? Then the time

can
be imported correctly. But, how can I input that little tick ' in a

routine
to do it automatically without it recognizing it as text???

Thanks.. mv




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default How to show a date and time with a ' in it???

Sorry Tom,

I had to give it a shot. Of course I ran into problems, but your code that
you did for me works great. Thanks for all your help. Hope that I can
return the favor someday!!!
Couldn't wait?

--
Regards,
Tom Ogilvy

"Michael Vaughan" wrote in message
...
Hello Everyone,

I am trying to setup a page so that I can import a excel file to my
Microsoft Outlook Calendar. I can do it manually, but I am trying to

write
a routine that will format the page for me. The problem is the time and
date. I have a routine that Tom Olgivy wrote for me:

Dim cell As Range
For Each cell In Range("A1:F10")
cell.Value = "'" & cell.Value
Next

It works for everything except the date and time. The problem is, when

it
see's the time with a ', it treats it as TEXT. Now, if I manually put

in
a
' before the time in the formula bar, it will take it??? Then the time

can
be imported correctly. But, how can I input that little tick ' in a

routine
to do it automatically without it recognizing it as text???

Thanks.. mv








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
Last data entry made time and Date show in each worksheet Rajat Excel Worksheet Functions 3 November 12th 06 01:27 PM
XY graph to show date and time ingalla Charts and Charting in Excel 3 November 7th 06 06:29 PM
Using Date & Time Custom Cell - Need to show blank! JDB Excel Discussion (Misc queries) 3 July 12th 06 01:34 PM
How to show current date and time vsr_kmb New Users to Excel 3 March 28th 06 04:09 PM
How do I format column containing date and time to only show the . ColoradoKid Excel Discussion (Misc queries) 5 December 18th 04 05:25 PM


All times are GMT +1. The time now is 02:21 PM.

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

About Us

"It's about Microsoft Excel"