LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Help with Copy based on dates code!

Hi all,

Can anybody please help, i have the code below that copies information
from a worksheet called 'Vehicles' to another sheet called 'Section
4' (from cell. It uses two dates on a worksheet called 'Title
Page' (cells B19 (Start dates) & 20 (Finish Date)).

The problem is that i get an error when there are no dates on the
vehicle sheet match the date range on the title page, anybody know how
i can ingore/remove this error?

Sub GetData_Vehicle_Install()

Application.ScreenUpdating = False

Dim sDate As Date, fDate As Date
Dim WS1 As Worksheet, WS2 As Worksheet

Set WS1 = Worksheets("Vehicles") '<== Change as required
Set WS2 = Worksheets("Section 4") '<== Change as required

WS1.Activate

With WS1
'assumes dates are in colum O
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row

sDate = Sheets("Title Page").Range("b19")
fDate = Sheets("Title Page").Range("b20")

Set dateRng = Range("D1:D" & LastRow)

r = Application.Match(CLng(sDate), dateRng, 1)
If IsError(r) Then
frow = 2 ' first row i.e. start date is before first date in
column A
Else
frow = r
End If
lRow = Application.Match(CLng(fDate), dateRng, 1)
.Cells(frow, 1).Resize(lRow - frow + 1).EntireRow.Copy
WS2.Range("a13") '' I GET THE ERROR ON THIS LINE!!

End With

Application.ScreenUpdating = True

End Sub


Many thanks in advance.

Cheers

P

 
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
Need code to copy and paste based on cell address. GoBow777 Excel Discussion (Misc queries) 1 July 13th 08 07:24 AM
Sum based on the dates in a different row. Gary Excel Worksheet Functions 1 February 8th 07 08:17 PM
How do I write a formula to color code based on dates provided or. jaime Excel Worksheet Functions 2 February 17th 05 12:41 AM
Code to copy range vs Copy Entire Worksheet - can't figure it out Mike Taylor Excel Programming 1 April 15th 04 08:34 PM


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