Run-time error '1004' : Method 'Range' of object'_Global' failed

  • Dear Experts,


    The below code works fine when run from the worksheet object.



    How ever when I run it from a userform option button



    I get the subject error.
    The debugger highlights the following line

    Code
    ws.PageSetup.PrintArea = ws.Range(Cells(1, 1), lastCell).Address


    Any Ideas?

  • Re: Run-time error '1004' : Method 'Range' of object'_Global' failed


    Quote from Grimes0332;768214

    LastCell is not initialised.


    How can I fix that? Sorry I'm not an expert in VBA

  • Re: Run-time error '1004' : Method 'Range' of object'_Global' failed


    You don't need to be a expert to see differences in the 2 procedures you posted.

  • Re: Run-time error '1004' : Method 'Range' of object'_Global' failed


    Dear Grimes0332,


    Thank you for the quick one liner insight. That fixed my mysery.


    Best Regards,

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!