![]() |
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 |
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 |
All times are GMT +1. The time now is 05:51 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com