+ Reply to Thread
Results 1 to 5 of 5

VBA code works in one SUB and fails in a different SUB

  1. #1
    Registered User
    Join Date
    05-25-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    19

    VBA code works in one SUB and fails in a different SUB

    Still trying to figure out Excel and would appreciate a little help.

    I need to make the current ROW be 1 row below the last row with data. If am using the following code:

    ActiveSheet.Range("A1").End(xlUDown).Offset(1).Select

    That code works in one SUB for a sheet my FORM refers to and fails in a SUB in the same FORM programming which is referring to a different sheet. I get the following error message only when trying the second SB referred to here.:

    Application-Defined or Object-Defined Error

    Needless to say I have beat my keyboard crazy before sending this message

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code works in one SUB and fails in a different SUB

    It's probably because it's a different sheet not a different sub.

    Also using xlDown can cause problems, use xlUp instead.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-25-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: VBA code works in one SUB and fails in a different SUB

    A big thanks for the quick help and excellent fix.

    I have been on other forms before that were not related to Excel. I have to admin that thios forum is the most informative and useful one I have seen. The folks who hang around here just seem to ne great folks.

    I am interest in what you meant about 'xlDown' giving problems.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code works in one SUB and fails in a different SUB

    If you use xlDown you could end up on the very last row in the worksheet.

    When you try to move down from that row you'll get the error you describe as you are trying to move off the worksheet.

  5. #5
    Registered User
    Join Date
    05-25-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: VBA code works in one SUB and fails in a different SUB

    You have a nice way of explaining things.

    Thanks and have a great day.

+ 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