Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem with date values

I'm trying to write a macro in Excel 2003. In this macro, I want to
use the date values of three different dates, but I'm not able to make
it work. The code below shows three different methods I've tried, but
they all just return 0. I have also tried using Double or Date instead
of Integer, but it turns out the same. When debugging this code, it
looks like the second range selection doesn't work. Any suggestions?

With ActiveSheet
.Range(.Cells(5, 9), Cells(7, 9)).Select
'...
Dim dateBefore As Integer
Dim dateSepTest As Integer
Dim dateAfter As Integer
dateBefore = .Range(.Cells(5, 1)).Value
dateSepTest = .Range(.Cells(6, 1)).Formula
.Range(.Cells(7, 1)).Select
dateAfter = Selection.Formula
MsgBox("dateBefore = " & dateBefore)
MsgBox("dateSepTest = " & dateSepTest)
MsgBox("dateAfter = " & dateAfter)
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Problem with date values

not sure what the question is but look at this

Option Explicit
Sub demo()
Dim d1 As Date
Dim d2 As Date
d1 = Range("C3").Value
d2 = Range("C4").Value
MsgBox "First date: " & d1
MsgBox "Next date: " & d2
End Sub

in your code you have
dateBefore = .Range(.Cells(5, 1)).Value
this is INDIRECTION
so .Cells(5, 1) (cell "A5") must be a valid cell reference like "B4" or a
named range, and "B4" would be the date
if thats NOT what you meant, then it ought perhaps be this:
dateBefore = .Cells(5, 1).Value


wrote in message
...
I'm trying to write a macro in Excel 2003. In this macro, I want to
use the date values of three different dates, but I'm not able to make
it work. The code below shows three different methods I've tried, but
they all just return 0. I have also tried using Double or Date instead
of Integer, but it turns out the same. When debugging this code, it
looks like the second range selection doesn't work. Any suggestions?

With ActiveSheet

xxx .Range(.Cells(5, 9), Cells(7, 9)).Select ''xxx
xxx '... 'xxx
Dim dateBefore As Integer
Dim dateSepTest As Integer
Dim dateAfter As Integer
dateBefore = .Range(.Cells(5, 1)).Value

dateBefore = .Range(.Cells(5, 1)).Value

dateSepTest = .Range(.Cells(6, 1)).Formula
.Range(.Cells(7, 1)).Select
dateAfter = Selection.Formula
MsgBox("dateBefore = " & dateBefore)
MsgBox("dateSepTest = " & dateSepTest)
MsgBox("dateAfter = " & dateAfter)
End With


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
Creating Intermediate Date Values - New Problem Jim Berglund[_2_] Excel Programming 2 April 30th 07 02:34 AM
Date Formula Problem - Leave date blank if Null Gayla Excel Worksheet Functions 5 April 24th 07 09:42 PM
How do I convert date values to non-date format e.g. 01-06-78? mikelenno Excel Discussion (Misc queries) 2 July 8th 05 08:51 PM
Date values Problem Subs Excel Programming 2 May 12th 05 03:46 PM
autofilter problem with date values Simon Sunke Excel Programming 0 April 4th 04 04:28 PM


All times are GMT +1. The time now is 06:04 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"