Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default find and copy rows based on dates in two columns

Hi
Sheet01 contains details of club members. Now I need a makro to find members
who were active on a certain date (or a perid), and copy those rows to Sheet02

Sheet01 has EnterDate in Col 1, ExitDate in Col 2
From a userform on Sheet03 i plan to get two dates from user: LastExitDate
and FirstEnterDate.

I suppose logic should be:

ExitDate empty or = LastExitDate (dont want those who left earlier)
EnterDate <= FirstEnterDate (dont want those who entered after)

Writing a macro that solves this is beyond my skills - any help is very
appreciated
Thank you!
ulf
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default find and copy rows based on dates in two columns

You need tot modify the constants StartDate and EndDate as required. You
also may need to changge the sheet names "Sheet1" and "Sheet2".

Sub movemembers()

Const StartDate As Date = "4/7/07"
Const EndDate As Date = "7/4/07"

With Sheets("Sheet2")
Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
End With
Sh2RowCount = Sh2LastRow + 1
With Sheets("Sheet1")
Sh1Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For Sh1RowCount = 1 To Sh1Lastrow
EnterDate = .Range("A" & Sh1RowCount)
ExitDate = .Range("B" & Sh1RowCount)
If IsDate(EnterDate) And IsDate(ExitDate) Then
If (EnterDate <= StartDate) And _
(ExitDate = EndDate) Then

.Rows(Sh1RowCount).Copy Destination:= _
Sheets("Sheet2").Rows(Sh2RowCount)

End If
End If
Next Sh1RowCount
End With

End Sub

"ulfb" wrote:

Hi
Sheet01 contains details of club members. Now I need a makro to find members
who were active on a certain date (or a perid), and copy those rows to Sheet02

Sheet01 has EnterDate in Col 1, ExitDate in Col 2
From a userform on Sheet03 i plan to get two dates from user: LastExitDate
and FirstEnterDate.

I suppose logic should be:

ExitDate empty or = LastExitDate (dont want those who left earlier)
EnterDate <= FirstEnterDate (dont want those who entered after)

Writing a macro that solves this is beyond my skills - any help is very
appreciated
Thank you!
ulf

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default find and copy rows based on dates in two columns

Thank you - that took me a long way.
One thing remains: all members have enter dates - but only some have exit
dates - these cells are empty

So I guess this has to be modified?

If IsDate(EnterDate) And IsDate(ExitDate) Then
If (EnterDate <= StartDate) And _
(ExitDate = EndDate) Then


Regards
ulf



"Joel" wrote:

You need tot modify the constants StartDate and EndDate as required. You
also may need to changge the sheet names "Sheet1" and "Sheet2".

Sub movemembers()

Const StartDate As Date = "4/7/07"
Const EndDate As Date = "7/4/07"

With Sheets("Sheet2")
Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
End With
Sh2RowCount = Sh2LastRow + 1
With Sheets("Sheet1")
Sh1Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For Sh1RowCount = 1 To Sh1Lastrow
EnterDate = .Range("A" & Sh1RowCount)
ExitDate = .Range("B" & Sh1RowCount)
If IsDate(EnterDate) And IsDate(ExitDate) Then
If (EnterDate <= StartDate) And _
(ExitDate = EndDate) Then

.Rows(Sh1RowCount).Copy Destination:= _
Sheets("Sheet2").Rows(Sh2RowCount)

End If
End If
Next Sh1RowCount
End With

End Sub

"ulfb" wrote:

Hi
Sheet01 contains details of club members. Now I need a makro to find members
who were active on a certain date (or a perid), and copy those rows to Sheet02

Sheet01 has EnterDate in Col 1, ExitDate in Col 2
From a userform on Sheet03 i plan to get two dates from user: LastExitDate
and FirstEnterDate.

I suppose logic should be:

ExitDate empty or = LastExitDate (dont want those who left earlier)
EnterDate <= FirstEnterDate (dont want those who entered after)

Writing a macro that solves this is beyond my skills - any help is very
appreciated
Thank you!
ulf

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default find and copy rows based on dates in two columns


I don't think the code needs to be modified based on your original
instructions. Empty cells will not meet the isdate test and will not be
included.


"ulfb" wrote:

Thank you - that took me a long way.
One thing remains: all members have enter dates - but only some have exit
dates - these cells are empty

So I guess this has to be modified?

If IsDate(EnterDate) And IsDate(ExitDate) Then
If (EnterDate <= StartDate) And _
(ExitDate = EndDate) Then


Regards
ulf



"Joel" wrote:

You need tot modify the constants StartDate and EndDate as required. You
also may need to changge the sheet names "Sheet1" and "Sheet2".

Sub movemembers()

Const StartDate As Date = "4/7/07"
Const EndDate As Date = "7/4/07"

With Sheets("Sheet2")
Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
End With
Sh2RowCount = Sh2LastRow + 1
With Sheets("Sheet1")
Sh1Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For Sh1RowCount = 1 To Sh1Lastrow
EnterDate = .Range("A" & Sh1RowCount)
ExitDate = .Range("B" & Sh1RowCount)
If IsDate(EnterDate) And IsDate(ExitDate) Then
If (EnterDate <= StartDate) And _
(ExitDate = EndDate) Then

.Rows(Sh1RowCount).Copy Destination:= _
Sheets("Sheet2").Rows(Sh2RowCount)

End If
End If
Next Sh1RowCount
End With

End Sub

"ulfb" wrote:

Hi
Sheet01 contains details of club members. Now I need a makro to find members
who were active on a certain date (or a perid), and copy those rows to Sheet02

Sheet01 has EnterDate in Col 1, ExitDate in Col 2
From a userform on Sheet03 i plan to get two dates from user: LastExitDate
and FirstEnterDate.

I suppose logic should be:

ExitDate empty or = LastExitDate (dont want those who left earlier)
EnterDate <= FirstEnterDate (dont want those who entered after)

Writing a macro that solves this is beyond my skills - any help is very
appreciated
Thank you!
ulf

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
Need Macro- Insert rows based on dates and copy info from that row Katerinia Excel Discussion (Misc queries) 1 April 6th 10 08:02 PM
How do I find and copy rows based on specific criteria? Georgew New Users to Excel 3 May 29th 09 11:07 AM
Find Duplicates Rows Based Own Multiple Columns Cue Excel Discussion (Misc queries) 2 June 20th 08 11:43 PM
Help with Copy based on dates code! [email protected] Excel Programming 2 June 17th 07 04:51 PM
Macro simplifying - copy rows to worksheets based on values in 2 different columns markx Excel Programming 1 February 27th 06 03:36 PM


All times are GMT +1. The time now is 09:37 AM.

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"