Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA Range.Offset Error 1004 Range beyond scope of sheet Dynamic Range

When the schedule is new and empty, the offset moves beyond the scope of the sheet and gives error 1004.
Needs a way to dynamically move up from the initially selected cell without error.
Some production lines drastically jump around the schedule which is why the offset up needs to be so great.

Option Explicit
Sub Print_Line_3()

    Dim lRow As Range
   
Application.ScreenUpdating = False
    With Sheets("Line 3")
        Set lRow = .Range("G1024").End(xlUp).Offset(-6, -6).Resize(24, 14)
        lRow.PrintOut
    End With
Application.ScreenUpdating = True

End Sub
' Starts from an arbitrary point then looks up to the last filled cell in that column.
' Moves from the selected cell up 6 then left 6 spots.
' Creates a selected range from previous cell to create a range to printout from.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Check the .Row first:

With Sheets("Line 3").Range("G1024").End(xlUp)
    If .Row > 6 Then
        Set lRow = .Offset(-6, -6).Resize(24, 14)
        lRow.PrintOut
    End If
End With
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading