Copy dates from one sheet to another in range if date is old than 11 months

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
203
Office Version
  1. 2013
Platform
  1. Windows
I am having an issue pulling dates from one workbook.sheet to another workbook.sheet. I've been working through the code. not sure if this is close or not.

The due1st spreadsheet's name will change daily. Need the code to reflect that also.

VBA Code:
Dim sh As Worksheet, lr As Long, rng As Range, sh2 As Worksheet, lr2 As Long, c As Range
Set sh = Workbooks("Training Matrix.xls").Worksheets("Current Emp") 'Edit sheet name - Source
Set sh2 = Workbooks("DUE1st" & "*" & ".xls").Worksheets("Sheet1") 'Edit Sheet name - Destination
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("F6:BB400" & lr)
For Each c In rng
If DateValue(c.value) <= Workbooks("Training Matrix.xls").Worksheets("Current Emp Key").Cells("I2") Then
'DateValue(Date) Then
lr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row + 1
c.EntireRow.Copy sh2.Range("A" & lr2)
End If
Next
 
You didn't mark your workbook for sharing so I'm not able to download it.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
VBA Code:
lLastRowSrc = oWsCurrEmp.Cells(Rows.Count, 6).End(xlUp).Row
Row count says 1048756. I believe its not finding the data.
I'm stumped. It should return the last occupied row in lLastRowSrc since there's data in column 6 (according to your GoogleDoc workbook). In case of no data at all, it should return 1, so this is a true mystery I'm not able to solve at present.
 
Upvote 0
at glance it almost appears that it isnt detecting the sheet... but not sure... maybe has something to due with date's rather than numbers?
 
Upvote 0
You might consider to set up an (anonymized) workbook with all your code in it and make it downloadable (not just viewable). At distance I'm not able to check and without a representative workbook I cannot test.
 
Upvote 0
got that part to move through i added this

VBA Code:
owscurremp.activate

prior to

VBA Code:
1lastrowsrc = owcurremp.cells(rows.count,1.end(xlup).row + 1

How now its hung up at

VBA Code:
If DateValue(c.value) <= dtCompDate Then
 
Upvote 0
You might consider to set up an (anonymized) workbook with all your code in it and make it downloadable (not just viewable). At distance I'm not able to check and without a representative workbook I cannot test.
I dont know how to do that :(
 
Upvote 0
Which part: replacing sensitive data with dummy data or sharing your workbook on GoogleDocs?
 
Upvote 0
The area i guess im struggling most in this code is below.

VBA Code:
    Set rng = oWsCurrEmp.Range("F6:BB" & lLastRowSrc)
    For Each c In rng
        If DateValue(c.value) <= dtCompDate Then
            lLastRowDest = oWsDue.Cells(Rows.Count, 1).End(xlUp).Row + 1
            c.EntireRow.Copy oWsDue.Range("A" & lLastRowDest)
        End If
    Next

Not really understand what c is an how it relates to each individual cell. I see that it is grabing the correct start date though.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top