Results 1 to 3 of 3

Subscript out of range error

Threaded View

intex Subscript out of range error 04-23-2015, 02:17 PM
Norie Re: Subscript out of range... 04-23-2015, 02:18 PM
intex Re: Subscript out of range... 04-23-2015, 02:33 PM
  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    englang
    MS-Off Ver
    Excel 2010
    Posts
    152

    Subscript out of range error

    Hi vba gurus,

    I have an issue with the code below, I have added more than 35000 into "Update" sheet and suddenly code came up with the error saying Overflow, when I press debug it highlights a line which i made below yellow.

    But when I hover over the red "vInfo" it says "Subscript out of range" it is very odd because when i had only 25000 records all worked fine.

    Could somebody be so kind and fix the code below.

    Private Sub TransferData()
        Dim c As Integer
        Dim i As Integer
        Dim iNew As Long
        Dim vInfo As Variant
        Dim wksSource As Worksheet
        Dim wksTarget As Worksheet
        
        Set wksSource = Sheets("Update")
        Set wksTarget = Sheets("Data Collection")
        vInfo = wksSource.Range("A2:B" & wksSource.Range("A100000").End(xlUp).Row)
        
        For i = LBound(vInfo, 1) To UBound(vInfo, 1)
            If vInfo(i, 1) = sOrder Then
                lstInfo.AddItem
                c = lstInfo.ListCount - 1
                lstInfo.List(c, 0) = vInfo(i, 1)
                lstInfo.List(c, 1) = vInfo(i, 2)
            End If
        Next i
        
        If lstInfo.ListCount > 0 Then
            c = c + 1
            TextBox1.Visible = True
            
            iNew = wksTarget.Range("C100000").End(xlUp).Row + 1
            
            
            wksTarget.Range("A" & iNew).Resize(c, 1) = CDate(Me.txtDate.Value)
            wksTarget.Range("B" & iNew).Resize(c, 1) = txtWeek.Value
            wksTarget.Range("C" & iNew).Resize(c, 1) = sOperator
            wksTarget.Range("D" & iNew).Resize(c, 1) = sTime
            wksTarget.Range("E" & iNew).Resize(c, 1) = txtCustom.Text
            wksTarget.Range("F" & iNew).Resize(c, 1) = txtComments.Text
            wksTarget.Range("G" & iNew).Resize(c, 1) = txtTimemin.Text
            wksTarget.Range("H" & iNew).Resize(c, 2) = lstInfo.List
             wksTarget.Range("I" & iNew).Resize(c, 4).Copy
              wksTarget.Range("I" & iNew).Resize(c, 1).PasteSpecial xlPasteValues
              Application.CutCopyMode = False
               ElseIf lstInfo.ListCount = 0 Then
            c = c + 1
            TextBox1.Visible = True
            iNew = wksTarget.Range("C100000").End(xlUp).Row + 1
            
             wksTarget.Range("A" & iNew).Resize(c, 1) = CDate(Me.txtDate.Value)
            wksTarget.Range("B" & iNew).Resize(c, 1) = txtWeek.Value
            wksTarget.Range("C" & iNew).Resize(c, 1) = sOperator
            wksTarget.Range("D" & iNew).Resize(c, 1) = sTime
            wksTarget.Range("E" & iNew).Resize(c, 1) = txtCustom.Text
            wksTarget.Range("F" & iNew).Resize(c, 1) = txtComments.Text
            wksTarget.Range("G" & iNew).Resize(c, 1) = txtTimemin.Text
            wksTarget.Range("H" & iNew).Resize(c, 1) = Left(txtOrder, 6)
            
        End If
    End Sub
    Last edited by intex; 04-23-2015 at 02:30 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  2. Runtime Error - Subscript out of Range / Object Error
    By JHRice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2012, 05:14 PM
  3. Defining Array - Runtime error 9, Subscript out of range error
    By MaartenW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2012, 07:32 AM
  4. Runtime Error - Subscript out of range despite On Error statement
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2006, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1