Solved What is wrong with this Macro for auto filling date.

January 21, 2017 at 10:32:53
Specs: Windows 10
When you enter the date on the spreadsheet and choose the add date to TAB button I get an error. what have done wrong???? THANKS!

Sub Tab_Date_2()
'
' Tab_Date_2 Macro
'

'
Range("M5").Select
Selection.Copy
Sheets("2-Jan-17").Select
Sheets("2-Jan-17").Name = "2-Jan-17"
Range("L5").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "DATE"
Range("J6:M6").Select
End Sub


See More: What is wrong with this Macro for auto filling date.

Report •

#1
January 23, 2017 at 05:58:09
✔ Best Answer
Let's start with a posting tip for asking a question in a help forum:

Telling us that you "get an error" doesn't give us much to work with. Since we don't know how your spreadsheet or macro environment is set up, we can't really test your code in a manner that might produce the same error.

What error are you getting? What instruction is causing the error? Have you tried single stepping through the code to help you determine where the problem might be?

That said, I don't understand what the code is supposed to be doing.

Issue #1:

Range("M5").Select
Selection.Copy

You copy M5 and then never do anything with the copied value.

Issue #2

Sheets("2-Jan-17").Select
Sheets("2-Jan-17").Name = "2-Jan-17"

You Select the sheet named "2-Jan-17" and then you rename it with the same name. What is the reason for doing that?

This part seems OK:

Range("L5").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "DATE"
Range("J6:M6").Select

OK, you are putting the word "DATE" in 2-Jan-17!L5 and then Selecting the range
2-Jan-17!J6:M6. I guess that makes sense. I wouldn't do it that way, but it gets the job done if that's what you need.

Perhaps if we knew what you are trying to accomplish, we could be of more assistance.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •
Related Solutions


Ask Question