Error 91(Subscript Out of Range)

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
779
Office Version
  1. 365
Hi,

I have a workbook with two sheets one called CDA_INVOICES and the other USD_INVOICES the code works fine in sheet CDA_INVOICES but USD one give me error 91, any suggestion.

Code:
VBA Code:
Sub PRINT_USD_DUE()
Dim rngToPrint As Range
    Dim datefilter As String
    
    On Error GoTo error_handler
    
    Application.ScreenUpdating = False
    
                        
    ' sort by invoice date (so the databodyrange isn't broken up into discontiguous rows
    Worksheets("USD_INVOICES").ListObjects("T_INV").Sort.SortFields.Clear
    Worksheets("USD_INVOICES").ListObjects("T_INV").Sort.SortFields. _
        Add2 Key:=Range("T_INV[[#Headers],[#Data],[DUE DATE]]"), SortOn:= _
        xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("USD_INVOICES").ListObjects("T_INV").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

With Worksheets("USD_INVOICES").PageSetup
    .PrintArea = Worksheets("USD_INVOICES").ListObjects("t_inv").Range.Address
    .CenterHorizontally = True
    .CenterVertically = False
    .PrintTitleRows = ("$A$14:$F$14")
    Worksheets("USD_INVOICES").Columns(8).Hidden = True
    Worksheets("USD_INVOICES").Columns(9).Hidden = True
    Worksheets("USD_INVOICES").Columns(10).Hidden = True
    Worksheets("USD_INVOICES").Columns(11).Hidden = True
    
    .Orientation = xlLandscape 'xlPortrait
    '.FitToPagesTall = 1
    .FitToPagesWide = 1

End With

Worksheets("USD_INVOICES").PrintPreview
Worksheets("USD_INVOICES").Columns(8).Hidden = False
Worksheets("USD_INVOICES").Columns(9).Hidden = False
Worksheets("USD_INVOICES").Columns(10).Hidden = False
Worksheets("USD_INVOICES").Columns(11).Hidden = False
    
error_handler:
    Select Case Err.Number
        Case 0
        Case Else
            MsgBox Err.Description & vbCrLf & vbCrLf & "Error no. " & Err.Number
    End Select
    
        
    Application.ScreenUpdating = True

End Sub

Thanks
 
yes, since I starting posting in this forums have learned a lot really grateful and appreciate all the help and tips i get from here.


thanks
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top