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

I'm not at my own computer now, but I'll give your solution a try later
today.

I should note that I had been using the select case date1 to date2 method
because my form allowed two methods of date range entry. Which one is used
is controlled by optionbuttons and an if statement in the code. The
simplest, and probably most used method would be to go by the year, as I
presented and you modified below. The other method was to allow a specific
date range, like 7/1/05 to 12/31/05. When the user chooses this method, the
textbox entries are changed to date variables:
If IsDate(textbox1) Then
date1 = Dateserial(year(textbox1),month(textbox1),day(text box1))
End If
....and the same for date2 and textbox2, the code I presented previously
would then work nicely by either specifying the year or a date range.
I try to simplify the problems I'm having when I present something to the
discussion group. I should say now that I had similar problems with using
7/1/05 to 12/31/05 as well.

Again, I'll try this method and reply later today or tomorrow when I've had
a chance to try it.

"Ardus Petus" wrote:

Sub test()
Dim sh As Worksheet
Dim c As Range
Dim myYear As Integer

myYear = Combobox1.Value
For Each sh In ThisWorkbook.Worksheets
For Each c In sh.Range("A1:A366")
If Year(c.Value) = myYear Then
MsgBox "Cell: " & c.Address & _
"=" & Format(c.Value, "dd/mm/yyyy")
End If
Next c
Next sh
End Sub


HTH
--
AP

"drhalter" a écrit dans le message de
...
Hi, I'm using a form to define a date range within which VB will extract

data
of transactions (like in a checkbook) from my workbook. The data is then

put
into a new file. The transactions range in date from 9/2004 to 4/2006.
There are several sheets (my test model contains only two). When I ask

the
program to give me all the transactions from 2005, I get all the data from
sheet1 in 2005 plus one in 2006 (and it is always the 3/18/2006, and it is
surrounded by many others from 2006), I get the first half of 2005 from
sheet2. This is when sheet1 is activated at runtime. If sheet2 is

activated
at runtime, I don't get the data from 2006, but the rest of the data is
approximately the same. The problem data from 2006 is from sheet1.

Here is a sample of my code (a bit distilled).
sheets(1).activate 'if I vary the integer in this line, the results

are
different

dim date1 as date
dim date2 as date
date1 = dateserial(combobox1,1,1)
date2 = dateserial(combobox1,12,31)

dim sh as worksheet
dim c as variant
dim myrange as range
For Each sh In ThisWorkbook.Worksheets
With Sheets(sh.Name)
Set myrange = .Range("A1", "A365")
End With
For Each c In myrange
Select Case cells(c.row,1) 'date of transaction is in column

one
Case date1 to date2
'code to export to array, might as well be _
'a messagebox displaying cells(c.row,1) for debugging

purposes
End select
Next c
Next sh

I hope someone has an idea, I can't think of why this isn't behaving
properly. I've tried retyping the raw data in the workbook. I've also

tried:
dim testdate as date
testdate =
dateserial(year(cells(c.row,1)),month(cells(c.row, 1)),day(cells(c.row,1)))
and then using testdate in the Select statement instead of cells(c.row,1).

I get similar problems with 2004. I don't seem to have trouble with 2006,
though I suppose if I added some 2007 transactions I could have the same
difficulty when attempting to use 2006.

Any ideas on where to go from here?
Thanks,
Dave




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
IF(AND with date comparison PSU35 Excel Worksheet Functions 4 October 27th 09 03:14 PM
Date Comparison Vic Excel Discussion (Misc queries) 1 October 22nd 09 03:18 PM
Date comparison TomD Excel Discussion (Misc queries) 4 February 20th 07 10:37 PM
Date comparison Darkdrew Excel Worksheet Functions 7 March 23rd 06 04:22 PM
Date comparison Jonibenj Excel Discussion (Misc queries) 6 October 23rd 05 08:34 PM


All times are GMT +1. The time now is 09:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"