Macro to use everyday that moves rows from one sheet to another

dtarockoff

New Member
Joined
Jun 26, 2013
Messages
24
I have a list of properties that I constantly add to, and each of these properties has a column with a date expressing when its loan expires. I want to create a macro that I can run everyday that will automatically pull out the properties whose date has passed [not sure if =IF statements using "< TODAY()" work for that part]. I want the ENTIRE row pulled from the existing sheet and placed at the BOTTOM of a new sheet (bottom of the data, not bottom of the whole sheet, obviously). I have formatted the two sheets the exact same so that the data will still be aligned with the correct columns when shifted over. Is this possible to create a macro for?

Let me know if this makes sense or if any further information is needed! Also, I just assumed macros were necessary, so if there's a formula that can get this done, even better.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I suppose the column that the date is in falls under company confidential, since you didn't share that with us.
However, Here is a procedure assuming that the date is in column C. If it is not then you can make the necessary change to the macro to substitute the correct column. You will also need to edit the sheet names. The prcedure will use sheets 1 and 2, with sheet 1 being the sheet of property listings that you update. Further assumtion is that the dates use the system format.
Code:
Sub expDate()
Dim sh1 As Worksheet, sh2 As worksheet, lr As Long, rng As Range, c As Range
Set sh1 = Sheets(1) 'Edit sheet name
set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells(Rows.Count, "C").End(xlUp).Row 'If col C is not the date column, change this and the next line.
Set rng = sh1.Range("C2:C" & lr) 'If col C incorrect substitute here and line above.  don't confuse with c variable.
 For Each c In rng
     If c.Value <= Date Then
          c.EntireRow.Copy sh2.Cells(Rows.Count).End(xlUp)(2)
     End If
 Next
End Sub
 
Upvote 0
Hmm I'm having trouble getting that code to work...not sure what the problem this. This is what I have pasted (minus the quotation marks at beginning and end):

"Sub expDate()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range
Set sh1 = "Master Log"
Set sh2 = "Expired Loans"
lr = sh1.Cells(Rows.Count, "I").End(xlUp).Row 'If col C is not the date column, change this and the next line.
Set rng = sh1.Range("I2:I" & lr) 'If col C incorrect substitute here and line above. don't confuse with c variable.
For Each c In rng
If c.Value <= Date Then
c.EntireRow.Copy sh2.Cells(Rows.Count).End(xlUp)(2)
End If
Next
End Sub"

I put quotation marks around the sheet names because it wouldn't let me use a space in the name without them. Maybe that's the issue; can't rename them though at this point as they're named that in plenty of other formulas so it'd be a hassle to change.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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