+ Reply to Thread
Results 1 to 5 of 5

subscript out of range

Hybrid View

josros60 subscript out of range 01-16-2013, 04:27 PM
6StringJazzer Re: subscript out of range 01-16-2013, 08:08 PM
josros6074 Re: subscript out of range 01-17-2013, 02:15 PM
josros6074 Re: subscript out of range 01-17-2013, 03:58 PM
6StringJazzer Re: subscript out of range 01-17-2013, 06:33 PM
  1. #1
    Registered User
    Join Date
    05-18-2005
    Posts
    17

    subscript out of range

    I have a spreadsheet in excel named "writeoff" and I print every month a report from a website in excel format.
    then i have a macro to link the report printed from website by the way name of file is "ReportProxyServlet" to cells on writeoff sheet by account number.

    But every time i run the macro I am getting this error "run time error 9, subscript out of range".
    I am attaching the two files.

    here it's the code:

    Private Sub CommandButton1_Click()
    Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, nRw As Long, e As Range, fVal As Range
     Set sh1 = ThisWorkbook.Sheets("WRITEOFF") 'Edit sheet name
     Set sh2 = Workbooks("ReportProxyServlet").Sheets("ReportProxyServlet") 'Edit workbook and sheet name
     lr = sh1.Cells(Rows.Count, 1).End(xlUp).Row
     nRw = sh2.Cells(Rows.Count, 1).End(xlUp).Row
     Set rng = sh1.Range("A2:A" & lr)
     For Each e In rng
     Set fVal = sh2.Range("A2:A" & nRw).Find(e.Value, LookIn:=xlValues)
     If Not fVal Is Nothing Then
     sh1.Range("E" & e.Row) = fVal.Offset(0, 2).Value
     End If
     Next
    End Sub
    thank you
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: subscript out of range

    The workbook ReportProxyServlet is not open when you run this macro. If this file exists you need to open it first to be able to refer to it in the Workbooks collection.

    Modify your code to look like this. This assumes that the file is in the same folder as this workbook. If not, modify the call to Open to include the correct path:
       Dim wb As Workbook
       Set wb = Workbooks.Open(ThisWorkbook.Path & "\ReportProxyServlet.xls")
       
       Set sh2 = wb.Sheets("ReportProxyServlet") 'Edit workbook and sheet name
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    07-09-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: subscript out of range

    Thank you.

    I modified with your suggestion don't get error anymore but the amounts from "ReportProxyServlet" report doesn't transfer to column e on "WRITEOFF" worksheet.

    for exam writeoff sheet has a column with account numbers that match ReportProxyServlet accounts number, so I want the macro to look for the accounts # that have amounts to transfer to writeoff sheet.

    thanks again.

  4. #4
    Registered User
    Join Date
    07-09-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: subscript out of range

    I thought about it, and i think what need help is in the same code to add vlookup function to look for the account find the amount and post it to to writeoff she in the in the right cell.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: subscript out of range

    Your new question is not related to your original question. You may be a better response by starting a new thread.

+ 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