none
error 1004 vba application-defined or object-defined error RRS feed

  • Question

  • Hi all, the following might help scam, visual throws me the following error: 
    Error 1004 VBA defined by the application or failure - defined object. 
    I do not know why. 
      Annex I code, Greetings

    Sub promedios(cada, hojar, cade, ri, rd, ci, ct, rmedioi, rdsi, rperi, rmedior, rdsr, rperr)
    rengloni = 13
    renglond = 12
    rani = 13
    inicial = Sheets(1).Cells(8, 9).Value
    Final = Sheets(1).Cells(9, 9).Value + cada
    siguiente = inicial + cada
    per = Val(Formulario.TextBox1_20.Text) / 100
    Do Until IsEmpty(Worksheets(11).Cells(rengloni, cade).Value)
        dato2 = Val(Trim(Str(Worksheets(11).Cells(rengloni, cade).Value)))
        If dato2 >= siguiente Then
          Final = Worksheets(11).Cells(rengloni, cade).Value
          Sheets(hojar).Cells(renglond, ci).Value = inicial
          Sheets(hojar).Cells(renglond, ct).Value = Final
          Sheets(hojar).Cells(renglond, rmedioi) = Round((Application.WorksheetFunction.Average(Sheets(11).Range(Cells(rani, ri), Cells(rengloni, ri)))), 1)
          Sheets(hojar).Cells(renglond, rdsi) = Round(Application.WorksheetFunction.StDev(Sheets(11).Range(Cells(rani, ri), Cells(rengloni, ri))), 1)
          Sheets(hojar).Cells(renglond, rperi) = Round(Application.WorksheetFunction.Percentile(Sheets(11).Range(Cells(rani, ri), Cells(rengloni, ri)), per), 1)
          Sheets(hojar).Cells(renglond, rmedior) = Round((Application.WorksheetFunction.Average(Sheets(11).Range(Cells(rani, rd), Cells(rengloni, rd)))), 1)
          Sheets(hojar).Cells(renglond, rdsr) = Round(Application.WorksheetFunction.StDev(Sheets(11).Range(Cells(rani, rd), Cells(rengloni, rd))), 1)
          Sheets(hojar).Cells(renglond, rperr) = Round(Application.WorksheetFunction.Percentile(Sheets(11).Range(Cells(rani, rd), Cells(rengloni, rd)), per), 1)
          inicial = Final
          siguiente = inicial + cada
          renglond = renglond + 1
          rani = rengloni
        End If
        rengloni = rengloni + 1
    Loop
    End Sub

    Tuesday, October 14, 2014 6:59 PM

Answers

  • What line is highlighted when you get the error? If I were to guess, it is:

    Sheets(hojar).Cells(renglond, rmedioi) = Round((Application.WorksheetFunction.Average(Sheets(11).Range(Cells(rani, ri), Cells(rengloni, ri)))), 1)

    Which should be re-written (probably)


    Sheets(hojar).Cells(renglond, rmedioi) = Round((Application.WorksheetFunction.Average(Sheets(11).Range(Sheets(11).Cells(rani, ri), Sheets(11).Cells(rengloni, ri)))), 1)

    The same is true for all your range usage - Cells(...) alone defaults to the activesheet, so you need to fully specify the cells and range parents.
    Wednesday, October 15, 2014 7:42 PM

All replies

  • What line is highlighted when you get the error? If I were to guess, it is:

    Sheets(hojar).Cells(renglond, rmedioi) = Round((Application.WorksheetFunction.Average(Sheets(11).Range(Cells(rani, ri), Cells(rengloni, ri)))), 1)

    Which should be re-written (probably)


    Sheets(hojar).Cells(renglond, rmedioi) = Round((Application.WorksheetFunction.Average(Sheets(11).Range(Sheets(11).Cells(rani, ri), Sheets(11).Cells(rengloni, ri)))), 1)

    The same is true for all your range usage - Cells(...) alone defaults to the activesheet, so you need to fully specify the cells and range parents.
    Wednesday, October 15, 2014 7:42 PM
  • thank you very much, my problem was solved, Greetings
    Wednesday, October 15, 2014 8:04 PM