Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Creating Intermediate Date Values - New Problem | Excel Programming | |||
Date Formula Problem - Leave date blank if Null | Excel Worksheet Functions | |||
How do I convert date values to non-date format e.g. 01-06-78? | Excel Discussion (Misc queries) | |||
Date values Problem | Excel Programming | |||
autofilter problem with date values | Excel Programming |