+ Reply to Thread
Results 1 to 8 of 8

Compile Error, expecting Sub

  1. #1
    Registered User
    Join Date
    01-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    4

    Compile Error, expecting Sub

    Hi Guys,

    I am completely new to vba and was wondering if anyone could explain why this wont run for me?:

    Please Login or Register  to view this content.
    Whenever I try to run this I get a compile error which says that It was expecting a Sub, Function or Property and then highlights the "Sub" line
    Last edited by Rhubarb; 01-07-2010 at 08:56 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,526

    Re: Compile Error, expecting Sub

    It first looks like you are calling a workbook a worksheet

    Please Login or Register  to view this content.
    ws needs to be a worksheet.

    In order to test the code further, you should supply a sample workbook that you are using the code with.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Compile Error, expecting Sub

    What's this line suppose to be doing?

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    01-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Compile Error, expecting Sub

    Quote Originally Posted by Andy Pope View Post
    What's this line suppose to be doing?

    Please Login or Register  to view this content.
    Initialising both variables to one? Am I doing something horrifically wrong?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Compile Error, expecting Sub

    Only making up your own syntax

    It may be valid syntax in another language but it VBA it's an error.

    Please Login or Register  to view this content.
    So this will move you on to the error Dave pointed out.

  6. #6
    Registered User
    Join Date
    01-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Compile Error, expecting Sub

    Ah. Ok so it works when I split it on to 2 seperate lines. Thanks!

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,526

    Re: Compile Error, expecting Sub

    Are you looping through worksheets or just looping through column A in one worksheet?

  8. #8
    Registered User
    Join Date
    01-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Compile Error, expecting Sub

    After getting off to a poor start I finally got my code to do what I wanted. Thanks for the help

    Please Login or Register  to view this content.

+ 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