Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Between Dates Criteria

I want to be able to do something while inbetween dates. Start date is in D1
and End date is in D2. Across row 1 starting in G1 is dates (01/01/09,
02/01/09, etc...)

Sub Test1()

Range("G3:G5").Select
Selection.Copy

Range("G1").Select
Do While ((ActiveCell) = Range("D1"))
ActiveCell.Offset(0, 1).Select
If ((ActiveCell) <= Range("D2")) Then
Exit Do
End If
Loop
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Between Dates Criteria

See if this code is bettedr. Itried to figurre out what you where attempting
to execute in a better format.

Sub Test1()

RowCount = 1
Do While Range("D" & RowCount) < ""
FirstDate = Range("D" & RowCount)
SecondDate = Range("E" & RowCount)
If FirstDate = Range("D1") And _
SecondDate <= Range("D2") Then

Exit Do
End If

RowCount = RowCount + 1
Loop

Range("G3:G5").Copy _
Destination:=Range("D" & (RowCount + 2))

End Sub


"AirgasRob" wrote:

I want to be able to do something while inbetween dates. Start date is in D1
and End date is in D2. Across row 1 starting in G1 is dates (01/01/09,
02/01/09, etc...)

Sub Test1()

Range("G3:G5").Select
Selection.Copy

Range("G1").Select
Do While ((ActiveCell) = Range("D1"))
ActiveCell.Offset(0, 1).Select
If ((ActiveCell) <= Range("D2")) Then
Exit Do
End If
Loop
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Between Dates Criteria

Joel thanks for your help. Your code looks like it goes down a column and I
need my code to go across columns.

01/01/08 02/01/08 03/01/08 04/01/08 05/01/08 06/01/08 07/01/08

If D1 equals 02/01/08 and D2 equals 05/01/08 then paste contents of G3:G5 to
the cells below each date.

01/01/08 02/01/08 03/01/08 04/01/08 05/01/08 06/01/08 07/01/08
Test1 Test1 Test1 Test1
Test2 Test2 Test2 Test2
Test3 Test3 Test3 Test3
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Between Dates Criteria

This code does what I want it to but it looks very messy to me. Is their a
more efficient way of doing this?

Sub Test3()
Range("G3:G5").Select
Selection.Copy
Range("G1").Select
Do While ((ActiveCell) < Range("D1"))
ActiveCell.Offset(0, 1).Select
If ((ActiveCell) = Range("D2")) Then
Exit Do
End If
Loop
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(-2, 0).Select
Do While ((ActiveCell) = Range("D1"))
ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(-2, 0).Select

If ((ActiveCell) = Range("D2")) Then
Exit Do
End If
Loop
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Between Dates Criteria

Try this


Sub Test3()

ColCount = Range("G1").Columns
Do While Cells(1, ColCount) <= Range("D2")
If Cells(1, ColCount) = Range("D1") Then
Range("G3:G5").Copy
Cells(2, ColCount).PasteSpecial _
Paste:=xlPasteAll, _
Transpose:=True
End If
ColCount = ColCount + 1
Loop
End Sub

"AirgasRob" wrote:

This code does what I want it to but it looks very messy to me. Is their a
more efficient way of doing this?

Sub Test3()
Range("G3:G5").Select
Selection.Copy
Range("G1").Select
Do While ((ActiveCell) < Range("D1"))
ActiveCell.Offset(0, 1).Select
If ((ActiveCell) = Range("D2")) Then
Exit Do
End If
Loop
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(-2, 0).Select
Do While ((ActiveCell) = Range("D1"))
ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(-2, 0).Select

If ((ActiveCell) = Range("D2")) Then
Exit Do
End If
Loop

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
Report using dates as a criteria UKMAN Excel Worksheet Functions 1 March 4th 10 05:10 PM
Counting criteria with dates in Jan,Feb etc Michael B Excel Discussion (Misc queries) 3 December 8th 08 11:58 AM
Sumif criteria between two dates Steve R Excel Worksheet Functions 3 October 17th 08 11:04 AM
criteria + between dates [email protected] Excel Worksheet Functions 2 March 22nd 07 10:56 AM
how to sum using dates as a criteria Lius Excel Worksheet Functions 8 December 2nd 04 11:11 AM


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