LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
QB QB is offline
external usenet poster
 
Posts: 57
Default Determine Max and Min date in Column

I have a column containing date, well sort of, they are actually entered as
text (ie: '2009-Apr-30)

I need to determine the min and max date value in the column using vba

I created a routine which I thought would do the job but I keep getting a
Type mismatch error?

Dim iLastRow As Integer
Dim Mindt As Date
Dim Maxdt As Date
Dim Curdt As Date

SrcWks = "Données"
DesWks = "Rapport"

Worksheets(SrcWks).Select
Worksheets(SrcWks).Range("A1").Select
Selection.End(xlDown).Select 'Find the last row in the data series
iLastRow = ActiveWindow.RangeSelection.Row

'Determine Min and Max Dates to build the report on
Mindt = CDate(Worksheets(SrcWks).Cells(2, 5).Value)
Maxdt = Mindt
For x = 2 To iLastRow
Curdt = CDate(Worksheets(SrcWks).Cells(x, 5).Value)
If Curdt Maxdt Then Maxdt = Curdt
If Curdt < Mindt Then Mindt = Curdt
Next x

What I find curious is the fact that if I set the Curdt to a set Cells Value
instead of variable on x the code works (doesn`t loop though, but does not
return an error), but when I use x to define Curdt, I get the error.
Anyways, Could someone show me the proper way to tackle this issue.

Thank you,

QB
 
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
formual to determine if date falls on weekend, adjust date to Mond Bradley Excel Discussion (Misc queries) 4 November 21st 08 06:19 PM
Need a formula to determine if date falls within a date range then Corca Excel Worksheet Functions 2 September 19th 08 09:36 AM
How to programatically determine the start date and end date of a graph [email protected] Charts and Charting in Excel 1 November 7th 07 09:56 PM
Determine which column to use by date Mike Griffin Excel Worksheet Functions 5 March 2nd 06 01:18 PM
Using formulas to determine date in one cell based on date in anot Gary Excel Worksheet Functions 2 November 22nd 04 08:11 AM


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