For some reason my code compiles, but it won't insert anything into the sheet ArrayData for the Chart Generation....This section I speak of is towards the end of the code with a For/If loop...

Since there are many values and excel's series input has a character limit of 255, I am putting these values in an unused sheet....but they aren't showing up when the code writes... and now when I corrected my reference to sheet for the range before the loop seen below where it is all caps...I get an error saying Application-defined or object defined error


Private Sub cmdGraphs_Click()

    '*************************************************************************************'
    'The Code below is only for the Graphing Parameter inputs                             '
    '*************************************************************************************'
    Static Counter As Integer
    'Variable to keep track of the amount of graphs generated


    Dim graphName As String
    graphName = form2.textName.Text

    Dim slot As Integer, sheet As String
    'Verify that an item was selected
    If listSlot.ListIndex = -1 Then
    'If ListIndex is -1, nothing selected
        MsgBox "Select a slot number!"
    Else
             'If ListIndex not -1 inform user what was selected
        MsgBox "You selected: " & listSlot.Value
        'As a reference to the selected value
        slot = listSlot.Value
    End If

    If listSheet.ListIndex = -1 Then
        MsgBox "Select a Sheet"
    Else
        MsgBox "You selected: " & listSheet.Value
        sheet = listSheet.Value
    End If

    '*************************************************************************************'
    'The Code below is for setting up the table where the first graphs will be            '
    '*************************************************************************************'

    'Selects sheet for graphic puposes
    Sheets("Sheet2").Select
    Sheets("Sheet2").Cells(2, 1).Select


    'Begin Plotting Table Data
    Dim rang As Range
    Set rang = Range("A3")


    If Counter <> 0 Then
        rang.Offset(Counter, 0) = graphName
        rang.Offset(Counter, 1).Value = sheet
        rang.Offset(Counter, 2).Value = slot
        rang.Offset(Counter, 3).Value = "Formula to be written"
        rang.Offset(Counter, 4).Value = "Formula to be written"
        rang.Offset(Counter, 5).Value = "Formula to be written"

    Else

        'Table Setup
        Sheets("Sheet2").Cells(1, 1).Value = "Current Sheet: " & ActiveSheet.Name
        Sheets("Sheet2").Range("A1:F2").Interior.ColorIndex = 15
        Sheets("Sheet2").Cells(1, 1).Font.Name = "Lucida Calligraphy"
        Sheets("Sheet2").Cells(1, 1).Font.Size = 16
        Sheets("Sheet2").Range("A1:F2").Font.Italic = True
        Sheets("Sheet2").Cells(2, 1).Value = "Graph Name"
        Sheets("Sheet2").Cells(2, 2).Value = "Data Sheet: " & sheet
        Sheets("Sheet2").Cells(2, 3).Value = "Slot No. "
        Sheets("Sheet2").Cells(2, 4).Value = "TW AVG "
        Sheets("Sheet2").Cells(2, 5).Value = "Sigma %"
        Sheets("Sheet2").Cells(2, 6).Value = "Angle"
        Sheets("Sheet2").Columns("A:G").AutoFit


        rang.Value = graphName
        rang.Offset(0, 1).Value = sheet
        rang.Offset(0, 2).Value = slot
        rang.Offset(0, 3).Value = "Formula to be written"
        rang.Offset(0, 4).Value = "Formula to be written"
        rang.Offset(0, 5).Value = "Formula to be written"

        'Adds a sheet for Array sorting due to 255 character limit
        Worksheets.Add(After:=Worksheets(1)).Name = "Array Data" & Counter
    End If

    Sheets("Sheet2").Columns("A:G").AutoFit


    '*************************************************************************************'
    'Search Algorithm for user defined Slot Number                                        '
    '*************************************************************************************'
    Dim slotRang As Range, slotArr() As Variant, i As Long
'THIS IS WHERE THE ERROR IS
    Set slotRang = Worksheets(sheet).Range("P2", Range("P2").End(xlDown))
    slotArr = slotRang.Value


'This section is to  to search for the value the user selected which is slot and only 
'store the rows in this case into arrays and then to be parsed into another worksheet for 
'another code to be added to generate a graph

    For i = 2 To UBound(slotArr, 1)
        If slotArr(i, 1) = slot Then
            MsgBox ("In the Array Loop")
            Dim xRang As Range, xArr2() As Variant
            Set xRang = slotRang.Offset(0, 4)
            xArr2 = xRang.Value
            Dim arrDatax As Range
            Dim arrDatay As Range
            Set arrDatax = Worksheets("ArrayData" & Count).Range("A1", Range("A1").End(xlDown))
            arrDatax.Value = Application.Transpose(arrDatax(i, 1))
            Dim yRang As Range, yArr() As Variant
            Set yRang = slotRang.Offset(0, 5)
            yArr = yRang.Value
            Set arrDatay = Worksheets("ArrayData" & Count).Range("B1", Range("B1").End(xlDown))
            arrDatay.Value = Application.Transpose(arrDatay(i, 1))
        End If
    Next






    textName.Value = ""
    Counter = Counter + 1




    End Sub