+ Reply to Thread
Results 1 to 4 of 4

Not sure what this error is or how to fix it

  1. #1
    Registered User
    Join Date
    08-03-2012
    Location
    35.0456° N, 85.3097° W
    MS-Off Ver
    2010
    Posts
    35

    Not sure what this error is or how to fix it

    Please Login or Register  to view this content.
    When I try to run the above code I get a compile error that states:
    Compile Error:
    Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules
    I saw this code on another forum which seemed to work with other users. I running Excel 2010. thank you.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,011

    Re: Not sure what this error is or how to fix it

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Not sure what this error is or how to fix it

    Hi pooky,

    My speculation your module looks like this:
    Please Login or Register  to view this content.

    When it should look like this with the 'Public' declaration outside and before the first Subroutine or Function:
    Please Login or Register  to view this content.
    Lewis

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Not sure what this error is or how to fix it

    Hello pooky,

    Public variables and constants can only be declared in Standard VBA modules. Variables, Constants, Sub and Functions declared in Standard VBA modules are visible to all other parts of your VBA project.

    Variables or constants declared as public in Worksheet modules will throw this error. Move the statement to the top of any Standard Module in your project. If you don't have one then add it.
    How to Add a Standard VBA Module to Your Project
    1. Open the VB Editor by pressing the keys ALT+F11.
    2. Open the Project Explorer window using CTRL+R.
    3. Add a Module using the keys ALT+I then press the M key.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  2. Receiving following error “Complie error : syntax error” Help
    By masond3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2012, 10:19 AM
  3. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  4. Error 75 File/Path access error, sometimes Error 1004
    By smokebreak in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-16-2011, 02:35 PM
  5. Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM

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