+ Reply to Thread
Results 1 to 4 of 4

"Subscript out of range" error

Hybrid View

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    "Subscript out of range" error

    Hello , below is my function. But my code throws error at "For Each " line as shown below


    Public Function displayExpectedValues()
    startRowValue = InputBox("Enter FirstRow Number to read data")
    EndRowValue = InputBox("Enter Last Row Number to read Data")
    
    For Each c In Sheets("Reasult Reader").Range("Q17:Q70") ' SubScript out of range error , thrown at this line.
        c.Offset(0, 2) = c.Offset(0, 1).Value + c.Offset(0, 3).Value
        startRowValue = startRowValue + 1
        If startRowValue = EndRowValue Then
              Exit For
        End If
    Next c
    End Function
    Can you please help me to remove this error ?

  2. #2
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: "Subscript out of range" error

    Eventhough i changed the function as given below , still the same error at shown line
    Public Function displayExpectedValues()
    startRowValue = InputBox("Enter FirstRow Number to read data")
    EndRowValue = InputBox("Enter Last Row Number to read Data")
    
    c = Sheets("Reasult Reader").Range("Q17") ' SubScript out of range error , thrown at this line.
    
    Do While startRowValue < EndRowValue
        c.Offset(0, 2) = c.Offset(0, 1).Value + c.Offset(0, 3).Value
        startRowValue = startRowValue + 1
    Loop
    End Function

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: "Subscript out of range" error

    A subscript out of range error occurs when the sheet name in the code does not match the sheet name in your file.

    Check that the sheet names match.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: "Subscript out of range" error

    Thank you very much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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