Link to home
Start Free TrialLog in
Avatar of antonioking
antoniokingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

if workbooks worksheets name is a date between date range, copy data to another workbook.

Please can someone help me.

I would like a macro that will open a workbook, and check the names of all the sheets in the workbook.
all names in the workbook follow the format... "CHAPS dd.mm.yy"
Where dd mm yy is a date.

If the name of the sheet is between specfied dates dteReportDate1 and dteReportDate2 then copy rows 3 onwards to the original workbook worksheet name "CHAPSWEEK1"

If there is already date on CHAPSWEEK1 the copied date should be appended to the sheet.
Sub RunCHAPSImport()
Dim strImportWorkBookName As String
Dim dteReportDate1 as Date
Dim dteReportDate2 as Date
Dim wbActiveWorkbook as Workbook

Set wbActiveWorkbook = ThisWorkbook
Set dteReportDate1 = "28/02/11"
Set dteReportDate1 = "07/03/11"

    Application.DisplayAlerts = False
    Set strImportWorkBookName = Workbooks.Open(Filename:="C:\InputFolder\CHAPS.xls")
    Application.DisplayAlerts = True

End Sub

Open in new window

Avatar of SiddharthRout
SiddharthRout
Flag of India image

Ok, the code is ready, however can you share a sample for both sheets so that I can get the references correct?

Sid
ASKER CERTIFIED SOLUTION
Avatar of SiddharthRout
SiddharthRout
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of antonioking

ASKER

type mismatch on line
dt = DateSerial(myarray(2), myarray(1), myarray(0))
Sorry try this

dt = DateSerial(Val(Trim(myarray(2))), Val(Trim(myarray(1))), Val(Trim(myarray(0))))

Sid
Now getting subscript out of range on that line. thanks
Can you upload the file so that I can test?

Sid