+ Reply to Thread
Results 1 to 5 of 5

new to vba- basic question

  1. #1
    Registered User
    Join Date
    05-04-2008
    Posts
    43

    new to vba- basic question

    Hi- I'm quite new to VBA and am going through a book trying to learn this...

    The book sets a basic task;

    Write a VBA statement that sets the value in the ActiveCell of the worksheet called This Sheet in the workbook called ThisBook to the value of 20

    So I manually set up a workbook called ThisBook and a worksheet called ThisSheet.

    This code did not work and a message comes up "Compile error: Sub or Function not defined". Could someone let me know why?? (also attached) - Thanks.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by shg; 05-04-2008 at 03:56 PM. Reason: added code tags

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please Login or Register  to view this content.
    Please read the Forum Rules about thread titles and Code Tags before starting your next thread.

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Also code should go in a module (See link)
    http://www.contextures.com/xlvba01.html#Regular

    Always try to avoid selecting whenever possible

    e.g

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  4. #4
    Registered User
    Join Date
    05-04-2008
    Posts
    43

    Ok

    OK-thanks. This works, but what if it is an not an absolute reference, but relative (ie the active cell?).

    Also, once I have set up a new module, should I use it for all other code within this workbook or keep setting up new modules?

    Quote Originally Posted by VBA Noob
    Also code should go in a module (See link)
    http://www.contextures.com/xlvba01.html#Regular

    Always try to avoid selecting whenever possible

    e.g

    Please Login or Register  to view this content.
    VBA Noob

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    This works, but what if it is an not an absolute reference, but relative (ie the active cell?).
    If it's for the activecell you don't need to specify the workbook and sheet

    Also, once I have set up a new module, should I use it for all other code within this workbook or keep setting up new modules?
    Up to you. If you have large blocks of code you may want to put each one in a module and rename the module to keep track of where the code is

    http://www.vbaexpress.com/training/l...m#_Toc80291116

    VBA Noob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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