+ Reply to Thread
Results 1 to 12 of 12

Discontinuous ranges

  1. #1
    Registered User
    Join Date
    05-13-2011
    Location
    Belfast, Northen Ireland
    MS-Off Ver
    Excel 2007
    Posts
    12

    Discontinuous ranges

    hi all

    im trying to select a discontinuous range within which my macro will run when changes are made.

    here is my code

    Please Login or Register  to view this content.
    this works well upto column BE, whenever i want to go beyond there it returns an error.

    any help would be appreciated!
    Last edited by davemcguire; 05-18-2011 at 11:27 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Discontinuous ranges

    Please Login or Register  to view this content.



  3. #3
    Registered User
    Join Date
    05-13-2011
    Location
    Belfast, Northen Ireland
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Discontinuous ranges

    snb

    thanks for that, but when i put that in the code it gives me this error message

    "compile error:variable not defined"

    and highlights the "cl" in your code, and the next line in mine.

    here is the full code if it helps

    Please Login or Register  to view this content.
    apologies if im being completely dense!

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Discontinuous ranges

    If you simply omit 'Option Explicit" it runs smoothly.

    Please Login or Register  to view this content.
    Last edited by snb; 05-18-2011 at 09:14 AM.

  5. #5
    Registered User
    Join Date
    05-13-2011
    Location
    Belfast, Northen Ireland
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Discontinuous ranges

    i must be being dense

    i removed the "option explicit" and now im getting a "Next without For" error and dont know why.

    if i remove the "next cell" command then it doesnt call the next instruction.

    how do i get this working?

  6. #6
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Discontinuous ranges

    add end if before the next statement

  7. #7
    Registered User
    Join Date
    05-13-2011
    Location
    Belfast, Northen Ireland
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Discontinuous ranges

    There already is an 'end if' before the 'next' statement.

    i really dont know whats gone wrong here, this code worked fine upto a certain no of ranges, and every suggestion leads to more errors, which leads me to believe there is something wrong with the code further down (as you guys are much better at this than me!)

    can someone help me sort this out?

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Discontinuous ranges

    Quote Originally Posted by davemcguire View Post
    snb

    thanks for that, but when i put that in the code it gives me this error message

    "compile error:variable not defined"

    and highlights the "cl" in your code, and the next line in mine.

    here is the full code if it helps

    Please Login or Register  to view this content.
    apologies if im being completely dense!

    Dear davemcguire,
    in the code that you entered in this post you need another end if because you have to if statements; that is what i was talking about i will check your other code and get back to you if this doesn't work

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Discontinuous ranges

    And please have a look in post #4

  10. #10
    Registered User
    Join Date
    05-13-2011
    Location
    Belfast, Northen Ireland
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Discontinuous ranges

    mohd - thanks for taking the time to look at 2 peices of code! if i add in a 2nd 'end if', it brings up a further error "end if without block if" !!

    snb - also thanks for your help in this, i did see your code and added it in, however it doesnt call the mail script and essentially nothing happens. I'm fairly new to vba, and i dont understand your code in the slightest, whereas i wrote mine (mostly) and at least have a rough idea what does what within the code.

    i think it may just be easier to limit the number of colums per worksheet!

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Discontinuous ranges

    Removing Option Explicit is not good practice or necessary. Try this version of your change event:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  12. #12
    Registered User
    Join Date
    05-13-2011
    Location
    Belfast, Northen Ireland
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Discontinuous ranges

    thats perfect romper, works a treat, thanks very much!

    thanks to everyone else who replied too, its much appreciated!

+ 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