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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,223,164
Messages
6,170,444
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