+ Reply to Thread
Results 1 to 8 of 8

Method 'Range' of object '_Global' failed when trying to apply a dynamic range to sheets

  1. #1
    Registered User
    Join Date
    04-18-2019
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    4

    Method 'Range' of object '_Global' failed when trying to apply a dynamic range to sheets

    Hi all, very new to VBA and would appreciate any help. I've been stuck on a problem that I can't seem to get past no matter what I try.

    I'm working with a file that has dozens of tabs. I have a calculation that dynamically sets a print range for each sheet in my workbook depending on the contents of that sheet. I am trying to develop a macro that will then delete all of the rows below where the print range ends in each sheet which will be a different row on each one.

    Currently I have the Macro working only on my active sheet - and whenever I try to apply it to each sheet I get the error Method 'Range' of object '_Global' failed. I'm assuming that this is because of the reference to ActiveSheet in the VBA but whenever I try to replace it I am getting the 'Object Required' error.

    I am completely stumped - would appreciate any help with this problem.

    Attaching a snippet below - here it only deletes the rows on the Active Sheet and when I try to apply a for each worksheet in this workbook component I get the Method 'Range' of object '_Global' failed error - how can I successfully delete the rows on each sheet?

    works on active sheet.PNG

  2. #2
    Registered User
    Join Date
    04-18-2019
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Method 'Range' of object '_Global' failed when trying to apply a dynamic range to shee

    This attempt results in an 'object required' error on the highlighted area

    Attachment 620739

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Method 'Range' of object '_Global' failed when trying to apply a dynamic range to shee

    Hi there,

    Welcome to the Forum.

    In general, posting your code as a picture is not very helpful as we can't copy it to a VBA CodeModule - it's much better to post your code as text surrounded by Code Tags.

    It's late at night here so, rather than re-typing all of your code, I'm just posting what I think you need to include in order to achieve what you want:

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  4. #4
    Registered User
    Join Date
    04-18-2019
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Method 'Range' of object '_Global' failed when trying to apply a dynamic range to shee

    Thanks for the help Greg - and noted about the text rather than pictures.

    When I run as per the below I get the error Method 'Range' of object '_Global' failed again on the 'Set PrintRange = ' line

    Here is how I altered what I had previously:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Method 'Range' of object '_Global' failed when trying to apply a dynamic range to shee

    This means the PrintArea isn't set yet on one of the sheets prior to running the code.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Method 'Range' of object '_Global' failed when trying to apply a dynamic range to shee

    Hi again,

    Many thanks for your feedback.

    Does the following code help to move things along:

    Please Login or Register  to view this content.

    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M

  7. #7
    Registered User
    Join Date
    04-18-2019
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Method 'Range' of object '_Global' failed when trying to apply a dynamic range to shee

    This has solved it! Can't thank you enough!

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Method 'Range' of object '_Global' failed when trying to apply a dynamic range to shee

    Hi again,

    Many thanks for your very prompt feedback and also for the Reputation increase - much appreciated!

    You're very welcome - glad I was able to help.

    Best regards,

    Greg M

+ 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. Replies: 3
    Last Post: 08-29-2016, 06:17 PM
  2. [SOLVED] Method 'Range' of object '_Global' Failed
    By jsmilke in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-12-2014, 05:49 PM
  3. Use of Named Range in VBA - Method 'Range' of object '_Global' Failed
    By hurst2008 in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 10-04-2013, 01:30 PM
  4. Method 'Range' of object'_Global' failed
    By arbulgazar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2013, 06:52 PM
  5. Method 'Range' of object '_global' failed
    By higherlimits in forum Excel General
    Replies: 3
    Last Post: 06-23-2006, 01:16 PM
  6. [SOLVED] method 'range' of object '_global' failed
    By Schades in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2005, 09:05 PM
  7. Method Range of object '_Global' failed
    By maverick2005 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2005, 10:05 AM

Tags for this Thread

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