+ Reply to Thread
Results 1 to 11 of 11

How to refer from a module to a specific worksheetsheet correctly?

  1. #1
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    17

    How to refer from a module to a specific worksheetsheet correctly?

    The problem is that if I run the following code manually within the worksheet ("Orders") as a macro, it works

    Please Login or Register  to view this content.
    When I call it from my userform, the call itself seems to work as well, but shows this code:

    Capture.PNG

    Which seems to indicate it doesn't refer to the sheet correctly. I have tried with ThisWorksheet instead of aActiveWorksheet, but to no avail.

    The actual error that shows is this:

    Capture.PNG

    Translated that means "The method Select for the class Range has failed"


    Any help is greatly appreciated!
    Last edited by Falkirk; 12-01-2016 at 06:17 PM. Reason: Rule 3 of our Forum RULES

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to refer from a module to a specific worksheetsheet correctly?

    Hello Falkirk,

    Welcome to the Forum.

    Moderation removed. Code Tags are added.
    Last edited by Winon; 12-02-2016 at 01:00 AM.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    17

    Re: How to refer from a module to a specific worksheetsheet correctly?

    Thanks I was pretty sure the PHP and HTML tags were not the right ones to use, just didn't see the #

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: How to refer from a module to a specific worksheetsheet correctly?

    How many workbooks are open when this macro runs?
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    17

    Re: How to refer from a module to a specific worksheetsheet correctly?

    1 workbook
    5 worksheets
    Start - Lists - Orders -Tips - Background

  6. #6
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: How to refer from a module to a specific worksheetsheet correctly?

    Hi,

    Your issue is that if you want to select cells you need to activate the sheet first i.e.

    Please Login or Register  to view this content.
    Regards,
    Stephen

    If you feel someone has helped you please thank them and click on the star on their post to add reputation.
    Please ensure that you use code tags where relevant, and mark solved threads as solved.
    Most of all please be respectful and understanding of others.

  7. #7
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    17

    Re: How to refer from a module to a specific worksheetsheet correctly?

    Works like a charm

  8. #8
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    17

    Re: How to refer from a module to a specific worksheetsheet correctly?

    Not sure if I should continue here, or make a new thread, but here goes..

    The altered code now works as intended, as long as there are emty rows to delete.
    when it parses this code:

    Please Login or Register  to view this content.
    It returns an error, if there are no blank cells to select.

    My question is then: How to I test if there are empty rows within my range before I try to delete them?

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to refer from a module to a specific worksheetsheet correctly?

    Hello Falkirk,

    One way is to try and add another line to the code;

    Please Login or Register  to view this content.
    Regards.

  10. #10
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    17

    Re: How to refer from a module to a specific worksheetsheet correctly?

    That feels a little like cheating, but I love the simplicity of the solution. Thanks alot!

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to refer from a module to a specific worksheetsheet correctly?

    Not really true in this case Falkirk, because what that line does is telling the code to move on if there are no Blanks in the Selection, instead of pestering you with an Error message.

    You are welcome, glad I could help.

    Thank you for the Rep, much appreciated!

    Regards.
    Last edited by Winon; 12-02-2016 at 04:20 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Trying to refer to a textbox in a userform from a module in a for next loop
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2015, 03:24 PM
  2. Replies: 0
    Last Post: 01-08-2013, 06:03 PM
  3. Replies: 1
    Last Post: 10-12-2012, 04:36 AM
  4. How to refer to specific cells in a specific scenario -or- alternative to scenarios?
    By lukaspanic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2012, 05:36 PM
  5. to refer to a textbox from a module
    By kmlprtsngh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2010, 03:05 AM
  6. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  7. [SOLVED] refer to specific worksheet
    By Dirk Nachbar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2006, 04:50 AM

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