Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Fighting a date format

I need the following to return the value of the cell, not the word "TRUE", I
have tried multiple ways to get this with no luck. Am sure it is an obvious
change.

For Each cell In Range("b:b")
If cell.Value Like "* Totals" Then
cell.Offset(5, 0) = IsDate(Range("C3"))
selection.NumberFormat = "m/d/yyyy"
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Fighting a date format

IsDate is a function that looks to see if a cell contains a date or not,
hence the TRUE value. Take that function away and you will get the contents
of C3 instead...

cell.Offset(5, 0) = Range("C3")

However, your next line is formatting the Selection... the offset cell you
just assigned the value to is not your selection. I *think* you may want
this instead...

cell.Offset(5, 0).NumberFormat = "m/d/yyyy"

--
Rick (MVP - Excel)


"jeremiah" wrote in message
...
I need the following to return the value of the cell, not the word "TRUE",
I
have tried multiple ways to get this with no luck. Am sure it is an
obvious
change.

For Each cell In Range("b:b")
If cell.Value Like "* Totals" Then
cell.Offset(5, 0) = IsDate(Range("C3"))
selection.NumberFormat = "m/d/yyyy"
End If


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Fighting a date format

The IsDate function returns True or False indicating whether the input
value is in fact a date. In your code, IsDate evaluates the contents
of C3 and if it is a date, IsDate returns True. If C3 is not a date,
IsDate returns False.

You can simply get rid of IsDate:

Change
cell.Offset(5, 0) = IsDate(Range("C3"))
to
cell.Offset(5, 0) = Range("C3").Value
or
cell.Offset(5,0) = Format(Range("C3").Value, "m/d/yyyy")


selection.NumberFormat = "m/d/yyyy"

This refers to the cell(s) that is presently selected, which very well
may not be cell.Offset(5,0). It is probably better to use

cell.Offset(5,0).NumberFormat = "m/d/yyyy"

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Fri, 6 Feb 2009 08:47:03 -0800, jeremiah
wrote:

I need the following to return the value of the cell, not the word "TRUE", I
have tried multiple ways to get this with no luck. Am sure it is an obvious
change.

For Each cell In Range("b:b")
If cell.Value Like "* Totals" Then
cell.Offset(5, 0) = IsDate(Range("C3"))
selection.NumberFormat = "m/d/yyyy"
End If

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Fighting a date format

On Feb 6, 9:47*am, jeremiah
wrote:
I need the following to return the value of the cell, not the word "TRUE", I
have tried multiple ways to get this with no luck. *Am sure it is an obvious
change.

For Each cell In Range("b:b")
* * If cell.Value Like "* Totals" Then
* * * * cell.Offset(5, 0) = IsDate(Range("C3"))
* * * * selection.NumberFormat = "m/d/yyyy"
* * End If


Jeremiah,

It may help for you to see how your program is behaving. You might
want to inswer the following code, step through your program (F8), and
watch the Immediate Window (View | Immediate Window).

For Each cell In Range("b:b")
Debug.Print "cell Addrs:"; cell.Address
If cell.Value Like "* Totals" Then
cell.Offset(5, 0) = IsDate(Range("C3"))
Debug.Print "cell Offset Addrs:"; cell.Offset(5,
0).Address
Selection.NumberFormat = "m/d/yyyy"
Debug.Print "selection Addrs:"; Selection.Address
End If
Next

I think you may be looking for the following (but I'm not sure because
I don't know what your exact objective is):

For Each cell In Range("b:b")
If cell.Value Like "* Totals" Then
If IsDate(cell.Offset(5, 0).Value) Then
cell.Offset(5,0).NumberFormat = "m/d/yyyy"
End If
End If
Next
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
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
change date format dd/mm/yyyy to Julian date format? itzy bitzy Excel Worksheet Functions 1 December 8th 09 07:42 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
fighting the type mismatch error mrmark[_5_] Excel Programming 2 June 24th 04 08:58 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


All times are GMT +1. The time now is 12:05 AM.

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"