+ Reply to Thread
Results 1 to 4 of 4

VBA Compile Error: Constant required

  1. #1
    Registered User
    Join Date
    11-05-2022
    Location
    London, England
    MS-Off Ver
    2020
    Posts
    6

    VBA Compile Error: Constant required

    Hi

    I'm new to VBA and was trying to make a code that allows me to add a day to the date each time the sheet gets printed.

    Sub DATE_PRINT()

    Const copies_to_print = 'enter the number of copies here
    Dim begin_date As Date
    Dim n As Integer

    begin_date = 'enter the beginning date here

    For n = 1 To copies_to_print Step 1

    ThisWorkbook.Sheets("Sheet1").Range("A1").Value = begin_date
    ThisWorkbook.Sheets("Sheet1").PrintOut COPIES:=1

    begin_date = begin_date + 1
    Next

    End Sub

    This is my code but it keeps saying constant required and Im unsure what to do. Any help would be appreciated

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Compile Error: Constant required


    Hi,

    just obviously fill the constant with a value like you can see in VBA help …

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,905

    Re: VBA Compile Error: Constant required

    It's because there is no value assigned to the constant after the = sign.


    Maybe it would be useful to get the number of copies and the date each time?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-05-2022
    Location
    London, England
    MS-Off Ver
    2020
    Posts
    6

    Re: VBA Compile Error: Constant required

    That works perfectly thank you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compile Error: Constant Expression required problem
    By el-paso in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2020, 04:41 PM
  2. [SOLVED] Compile Error: Object required
    By Tresfjording in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-21-2020, 06:13 AM
  3. Compile Error: compile error constant expression required.
    By countryfan_nt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2019, 04:45 AM
  4. [SOLVED] Compile Error Constant Expression Required
    By dloskot in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-10-2016, 02:46 PM
  5. Compile error (Constant expression required) when using macro twice
    By flunzy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-02-2014, 10:35 AM
  6. [SOLVED] Compile error: Constant expression required error when merging two Codes
    By Kezwick in forum Outlook Programming / VBA / Macros
    Replies: 8
    Last Post: 06-26-2013, 09:32 AM
  7. creating a public constant by concatenating string......gives compile error
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2011, 07:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1