New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Run-time error `9` subscript out of range

Macros, VBA, Excel Automation, etc.

Run-time error `9` subscript out of range

Postby christy » Wed Apr 24, 2013 1:27 pm

In Desperate Need!

I am over my head trying to fix a workbook for my employer, which was set up by someone no longer with their company. I am using Excel 2003 and I keep getting a Microsoft Visual Basic message “Run-time error `9` subscript out of range” then I debug and it highlights the 4th line of code in the Extract Module of this 12 sheet workbook.

4th line code as follows: Windows("CCN Dashboard.xls").Activate

The code for this module is below. Can anyone help point me in the right direction?

Thank you for your time and consideration!
Christy




Code: Select all
Sub ExtractData()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveSheet.Unprotect
Windows("CCN Dashboard.xls").Activate
Sheets("Front Page").Select

'===================================================================================
    'Checks that mandatory Data has been entered.
    Range("Date").Select
    If ActiveCell = "" Then
        MsgBox "You Must Enter a Date"
        Range("Date").Select
        GoTo lastline
    End If
       
    Range("Customer").Select
    If ActiveCell = "" Then
            MsgBox "You Must Enter A Customer Name"
            Range("Customer").Select
        GoTo lastline
    End If
       
    Range("Contact").Select
    If ActiveCell = "" Then
            MsgBox "You Must Enter a Customer Contact"
            Range("Contact").Select
        GoTo lastline
    End If
   
    Range("Email").Select
    If ActiveCell = "" Then
            MsgBox "You Must Enter a Customer Email"
            Range("Email").Select
            GoTo lastline
    End If
   
    Range("QE").Select
    If ActiveCell = "" Then
            MsgBox "You Must Enter a QE Name"
            Range("QE").Select
            GoTo lastline
    End If
   
    Range("Project").Select
    If ActiveCell = "" Then
            MsgBox "You Must Enter a Project#"
            Range("Project").Select
            GoTo lastline
    End If
   
      Range("Severity").Select
    If ActiveCell = "" Then
            MsgBox "You Must Enter a Severity Class"
            Range("Severity").Select
            GoTo lastline
    End If
   
   
    If Range("M101") = 0 Then
                MsgBox "You Must Enter a Def Quantity"
                Range("G15").Select
                GoTo lastline
    End If
       
    Range("G18").Select
    If ActiveCell = "" Then
                MsgBox "You Must Enter a Problem Description"
                Range("G18").Select
                GoTo lastline
    End If
   
    Range("Lot").Select
    If ActiveCell = "" Then
                MsgBox "You Must Enter Lot#"
                Range("Lot").Select
                GoTo lastline
    End If
       
    Range("Sort").Select
    If ActiveCell = "" Then
                MsgBox "Is a SORT Required?"
                Range("Sort").Select
                GoTo lastline
    End If
   
    Range("Visit").Select
    If ActiveCell = "" Then
                MsgBox "Is an ESC Visit Required?"
                Range("Visit").Select
            GoTo lastline
    End If
   
    Range("Category").Select
    If ActiveCell = "" Then
                MsgBox "You Must Enter a Defect Category"
                Range("Category").Select
            GoTo lastline
    End If
 
  Range("Repeat").Select
    If ActiveCell = "" Then
                MsgBox "You must enter Yes or No"
                Range("Repeat").Select
            GoTo lastline
    End If
 
  Range("Dept").Select
    If ActiveCell = "" Then
                MsgBox "You Must Enter a Suspect Department"
                Range("Dept").Select
            GoTo lastline
    End If
 
  Range("DetDate").Select
    If ActiveCell = "" Then
                MsgBox "You Must Enter a Detection Date"
                Range("DetDate").Select
            GoTo lastline
    End If
 
  Range("DetPoint").Select
    If ActiveCell = "" Then
                MsgBox "You Must Enter a Detection Point"
                Range("DetPoint").Select
            GoTo lastline
    End If

'================================================================================
'Opens files
       ' Test to see if the file is open.
    If IsFileOpen("P:\Customer Complaint\CCN Files\Customer Complaint Check List.xls") Then
       MsgBox "Another User has the Check List! Please try again later"
       Sheets("Front Page").Select
      GoTo lastline
    Else
           Workbooks.Open "P:\Customer Complaint\CCN Files\Customer Complaint Check List.xls", UpdateLinks:=3
           
'Opens Quality Alert
       ' Test to see if the file is open.
    If IsFileOpen("P:\Customer Complaint\CCN Files\Quality Alert.xls") Then
       MsgBox "Another User has the Quality Alert! Please try again later"
       Sheets("Front Page").Select
      GoTo lastline
    Else
           Workbooks.Open "P:\Customer Complaint\CCN Files\Quality Alert.xls", UpdateLinks:=3
    End If
   
Programline:
Windows("CCN Dashboard.xls").Activate
Sheets("Front Page").Select
Range("Date").Copy
Sheets("Log").Select
Range("D2:D550").Select
    Selection.Find(What:="", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    ActiveCell.Offset(rowOffset:=0, columnOffset:=-1).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Activate
Sheets("Front Page").Select
Range("Data").Copy
Sheets("Log").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=True
ActiveCell.Offset(rowOffset:=0, columnOffset:=12).Activate
Sheets("Front Page").Select
Range("Data2").Copy
Sheets("Log").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=True
ActiveCell.Offset(rowOffset:=0, columnOffset:=-15).Activate

ActiveWorkbook.Save

ActiveCell.Copy
Windows("Customer Complaint Check List.xls").Activate
Sheets("List").Select
Range("Number").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=True
Windows("Quality Alert.xls").Activate
Sheets("Alert").Select
Range("Number").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=True


Windows("CCN Dashboard.xls").Activate
Sheets("Front Page").Select

'AACT Form
'===========================================

If Range("Customer") = "AACT" Then
   
Application.Run "'CCN Dashboard.xls'!AACTForm.AACTForm"

End If

'Denso Forms
'=======================================================================================
If Range("Customer") = "Denso" Then

Application.Run "'CCN Dashboard.xls'!DensoForms.DensoForms"

End If


'JATCO
'=======================================================================================
If Range("Customer") = "JATCO" Then

Application.Run "'CCN Dashboard.xls'!JATCOForm.JATCOForm"

End If


'NTTechno
'=======================================================================================
If Range("Customer") = "NT Techno" Then

Application.Run "'CCN Dashboard.xls'!NTTechnoForm.NTTechnoForm"

End If


'JTEKT
'=======================================================================================
If Range("Customer") = "JTEKT" Then

Application.Run "'CCN Dashboard.xls'!JTEKTForm.JTEKTForm"

End If


'Hitachi
'=======================================================================================
If Range("Customer") = "Hitachi" Then

Application.Run "'CCN Dashboard.xls'!HitachiForm.HitachiForm"

End If


'INA
'=======================================================================================
If Range("Customer") = "Schaeffler (INA)" Then

Application.Run "'CCN Dashboard.xls'!INAForm.INAForm"

End If


'Tsubaki
'=======================================================================================
If Range("Customer") = "UST" Then

Application.Run "'CCN Dashboard.xls'!TsubakiForm.TsubakiForm"

End If


'Ford and Other
'=======================================================================================
If Range("Customer") = "Ford" Then
Application.Run "'CCN Dashboard.xls'!FordOther.FordOther"
End If

If Range("Customer") = "CFMA" Then
Application.Run "'CCN Dashboard.xls'!FordOther.FordOther"
End If

If Range("Customer") = "CFME" Then
Application.Run "'CCN Dashboard.xls'!FordOther.FordOther"
End If

If Range("Customer") = "Comtech" Then
Application.Run "'CCN Dashboard.xls'!FordOther.FordOther"
End If

If Range("Customer") = "Mazda" Then
Application.Run "'CCN Dashboard.xls'!FordOther.FordOther"
End If

If Range("Customer") = "SPW" Then
Application.Run "'CCN Dashboard.xls'!FordOther.FordOther"
End If

'Other
'=======================================================================================
If Range("Customer") = "GHSP" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "GKN" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "GM" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "Honda" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "Nissan" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "NTN Bearing" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "NTN Driveshaft" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "Oiles" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "OSS" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "Showa" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "Toyota" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

If Range("Customer") = "Unisia" Then
Application.Run "'CCN Dashboard.xls'!Other.Other"
End If

'Clears the CCN Dashboard Fields
Windows("CCN Dashboard.xls").Activate
Sheets("Front Page").Select
Range("Clear1").Select
Selection.ClearContents
Range("Data2").Select
Selection.ClearContents
Range("Clear3").Select
Selection.ClearContents
Range("PartName").Select
Selection.ClearContents
Range("SearchQE").Select
Selection.ClearContents
Range("G7").Select
ActiveWorkbook.Save
lastline:
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


'=======================================================================================
MsgBox "Your New CCN Number is," & Chr(13) & "  " & Chr(13) & _
"     " & Range("CCNNumber").Value & Chr(13) & "  " & Chr(13) & _
"You can now open the CCN Form using the next screens!"
'=======================================================================================

'Opens a path to the Currect CCN Folder and allows the user to select the CCN just made
Dim Filter As String, Title As String
Dim FilterIndex As Integer
Dim filename As Variant
' File filters
Filter = "Excel Files (*.xls),*.xls," & _
        "Text Files (*.txt),*.txt," & _
        "All Files (*.*),*.*"
' Default Filter to *.*
FilterIndex = 3
' Set Dialog Caption
Title = "Select a File to Open"
' Select Start Drive & Path
ChDir ("P:\Customer Complaint\Current CCNs")
With Application
    filename = .GetOpenFilename(Filter, FilterIndex, Title)
End With
' Exit on Cancel
If filename = False Then
    MsgBox "No file was selected."
    Exit Sub
End If
' Open File
Workbooks.Open filename

'========================================
   
End Sub
  • 0

Last edited by Don on Thu Apr 25, 2013 2:59 am, edited 1 time in total.
Reason: please use code tags around your vba next time :)
christy
Rookie
 
Posts: 1
Joined: Apr 24, 2013
Reputation: 0
Excel Version: 2003

Re: Run-time error `9` subscript out of range

Postby Sisyphus » Thu Apr 25, 2013 9:12 am

Hello Christy.
Welcome to the forum!
The line Windows("CCN Dashboard.xls").Activate will return a "Subscript out of range" error if there is no window by that name. The workbook may have been renamed, or it isn't open when the code is run.
The workbook CNN Dashboard.xls should be a workbook other than the one in which the code you copied for us resides. This would be normal practise if the code came from an add-in.
  • 0

Have a great day! :D

Sisyphus
I do this for "honour and country" - much less of the latter, actually.
If I helped you, award points, plenty of them.
If I bored you, deduct points for being too long-winded. (I know, :lol)
Sisyphus
Former Moderator
 
Posts: 4454
Joined: Dec 7, 2011
Location: Shanghai
Reputation: 203
Excel Version: 2010


Return to Macros and VBA Questions

Who is online

Users browsing this forum: Majestic-12 [Bot] and 33 guests