Subtracting Dates to Last Row

loract

New Member
Joined
Apr 21, 2023
Messages
14
Office Version
  1. 365
Platform
  1. Windows
One of the things I am trying to do with a file is Subtract 10 days from a column A called "OUTDATE" and put the resulting date in Column J. This is how I am working it just now:

At the beginning of the sub I use this:

VBA Code:
lR = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row

'and then in the section where I am subtracting the dates, I use this:
 Dim i As Integer
   For i = 2 To lR
 
        Range("J" & i) = DateAdd("d", -10, Range("A" & i))
    Next i


This gives me an "Application-defined or object-defined error" and highlights the "Range" line. HOWEVER, the dates actually do work all the way to the last row. So it's almost like it does what I want it to do but then gives up. This is the last action of many that the macro does, so the next line is End Sub.

If I change the "For i" line to For i = 2 to 60 or some other number, the macro works fine as long as there are sixty columns or more (but it only gives me dates for rows 2 to 60). But if there are less than sixty it throws an error. I really need it to find the last row.

I'd appreciate any help!
Thanks!
 
You are welcome.
Yes, I don't think it like trying to go back ten days from nothing!

Glad I was able to help!
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,598
Messages
6,125,748
Members
449,258
Latest member
hdfarid

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