Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Dates in range not selecting properly

Apologies to all. I had assumed, naively, that the error was in the date
format, whereas, of course, the error was in my code. If the line:
ws.activate '(line 20 of my original code)
is moved up two lines so that the code now reads:

.......
For jrow = 1 To lastroww Step 1
ws.activate
datew = Range("A" & jrow).Value
If datew = datestart And datew <= dateend Then
With ActiveSheet
Rows(jrow).Copy
......

the code ensures that I select the date from the same worksheet from which I
subsequently copy the row. The old code might, after I had looped, select
a date from the correct row ('jrow') but from a different sheet from the
subsequently copied line.

Thanks to everyone for their help, and my apologies for wasting their time.


"Ardus Petus" wrote:

The code looks fine (though you could avoid selecting worksheets).
Now you must debug your code:
put a breakpoint on offending line
Run macro.
When it hits the breakpoint, check the values of your variables

HTH
--
AP

"Kanga 85" a écrit dans le message de
news: ...
Ardus Petus,

The code is pasted below. It looks alright to me, but it still selects
dates outside my range.

Any further help would be appreciated.
Thanks


' Macro recorded 10/05/2006 by Ray
'
' Keyboard Shortcut: Ctrl+f
' To cover all worksheets from "start" to "finish"

Dim lastrowdiv As Long, lastroww As Long, jrow As Long, datestart As
Date, dateend As Date, datew As Date, ws As Worksheet
Sheets("div05-06").Select
datestart = Range("A1").Value
dateend = Range("B1").Value
With ActiveSheet
lastrowdiv = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
If lastrowdiv = 2 Then
lastrowdiv = 3
End If
For jws = Worksheets("Start").Index To Worksheets("Finish").Index
Set ws = Worksheets(jws)
ws.Activate
With ActiveSheet
lastroww = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For jrow = 1 To lastroww Step 1
datew = Range("A" & jrow).Value
If datew = datestart And datew <= dateend Then
ws.Activate
With ActiveSheet
Rows(jrow).Copy
End With
Sheets("div05-06").Select
With ActiveSheet
.Rows(lastrowdiv).Select
ActiveSheet.Paste
lastrowdiv = lastrowdiv + 1
End With
End If
Next jrow
Next jws
End Sub




"Ardus Petus" wrote:

The code you post is correct (works by me).

The error might reside in some other part of your code.

Why not post your whole code (if not too big)

HTH
--
AP

"Kanga 85" a écrit dans le message de
news:
...
I want to select lines containing a range of dates from a series of
worksheets and to paste these lines into another "Results" worksheet.
The
sub works well, except that the date selection picks dates outside my
range.
With datestart = 1 Jan 2006, and dateend = 31 Dec 2006, the following
program picks all dates ('datews') within this range, but also gets
some
outside it.

'Dim datestart As Date, dateend As Date, datews As Date
'If datews = datestart And datews <= dateend Then
'.....
'End if

Any ideas?
Thanks







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
Please help VBA code not working properly send email when due dates Tia[_3_] Excel Worksheet Functions 0 July 21st 09 08:37 AM
selecting the first date in a range of dates shoun2me Excel Worksheet Functions 7 August 8th 07 07:02 PM
Dates don't appear properly after downloading data from Accounting r Excel Discussion (Misc queries) 4 June 15th 07 10:18 AM
OR(EXACT(Cell; Range)) does not work properly Dave Peterson Excel Worksheet Functions 4 January 1st 07 03:11 AM
Excel not recognizing Dates properly. Dan Excel Discussion (Misc queries) 1 March 23rd 05 07:19 PM


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