date today formula 1004 error in vba

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
Code:
  Columns("U:U").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("U1").Value = "Data"
        Range("U2").Select
            ActiveCell.FormulaR1C1 = "=DATE(Month(TODAY())&Date(TODAY()-20)& &LOW&L2&_INV&S2"
                Selection.AutoFill Destination:=Range("U2:U" & lastrow)
                    Range("U2:U" & lastrow).Select
                    Selection.Copy
                        Range("U2:U" & lastrow).Select
                        ActiveCell.PasteSpecial

For now. I have that code for getting data in U column.
I am trying to use date today formula to get date 20 days earlier. Then I am trying to copy whole row and paste in same column in order to remove formulas. However, I am getting run-time error '1004';

Is there any way to solve this problem?

Thank you!
 

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.
You need to put year in Date formula.
Please run this code. Especially last two lines close to what you want?

Code:
Sub test()
Range("A1").Value = "=date(month(today()),day(today()-20),2017)"
Range("A2").Value = "=today()-20"
Range("A3:A10").Formula = "=date(month(today()),day(today()-20),2016)"
Range("B3:B10").Value = Range("A3:A10").Value
Range("A11").Value = "=DATE(MONTH(TODAY()),day(TODAY()-20),2017) & ""_LOW"""
Range("A12").Value = "=text(DATE(2017,MONTH(TODAY()),TODAY()-20),""mm/dd/yyyy"") & ""_LOW"""
End Sub
 
Upvote 0
Thank you for your advise. But code you provided me doesn't work if I add column values like L2, and B2 like this
Range("A12").Value = "=text(DATE(2017,MONTH(TODAY()),TODAY()-20),""mm/dd/yyyy"") & ""_LOW"" &L2&"_"&B2
I get the error message in the cell. Is there way to put column values in the formula?

Thank you for your support!
 
Upvote 0
Not single, make it double ""_""
And it was my mistake. It needs Day formula Day(Today()-20).
 
Upvote 0

Forum statistics

Threads
1,216,167
Messages
6,129,262
Members
449,497
Latest member
The Wamp

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