+ Reply to Thread
Results 1 to 7 of 7

vba macro code error: statement invalide outside type block

  1. #1
    Registered User
    Join Date
    02-17-2012
    Location
    charlotte, nc
    MS-Off Ver
    Excel 2007
    Posts
    25

    vba macro code error: statement invalide outside type block

    I just started working with macros and the vba code. I have read online how to do what I want but when I run the code i get an error "statement invalid outside type block". Here is my code:
    Please Login or Register  to view this content.
    Maybe it has to do with my msgBox it highlights the top line in yellow, but the msgBox is highlighted in blue. Any help would be great! Thanks
    Last edited by satania; 02-20-2012 at 03:42 PM.

  2. #2
    Registered User
    Join Date
    02-17-2012
    Location
    charlotte, nc
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Help with vba macro code

    Well I got rid of the error but now my code doesn't work. Back to the drawing board

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: vba macro code error: statement invalide outside type block

    Does the following help?
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Help with vba macro code

    There were a couple of issues that you need to watch for.
    1. When using the worksheet change event, you should toggle enable events
    2. If you are going to reference a range like C9 then you have to explicitly call it as a range:
      Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-17-2012
    Location
    charlotte, nc
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Help with vba macro code

    Ah I see thanks. I haven't ran into that in any of the examples I looked at online.

  6. #6
    Registered User
    Join Date
    02-17-2012
    Location
    charlotte, nc
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: vba macro code error: statement invalide outside type block

    Actually using the code suggested gives me an error. I tried

    Please Login or Register  to view this content.
    got a run time error: method 'range' of object '_worsheet' failed. Did I miss something? I even took out the or's to see if it was messing it upso I just had one test in the if statement.

  7. #7
    Registered User
    Join Date
    02-17-2012
    Location
    charlotte, nc
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: vba macro code error: statement invalide outside type block

    Got it! I needed quotes around C9

+ 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