PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] VBA code: run-time error 1004 (application-defined or object-defined error)-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] VBA code: run-time error 1004 (application-defined or object-defined error)

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    2

    Resolved [RESOLVED] VBA code: run-time error 1004 (application-defined or object-defined error)

    Hi,

    I have a simple code in VB 6.5 used to copy a table of data from spreadsheet A to spreadsheet B

    The code stops when it tries to copy the data. Could you give me a hand to fix the problem?

    Thanks!

    Eric

    here is the code:
    Code:
    Windows("A.xls").Activate
       
    ' get the number of days
     
        Dim days_month  As Integer
       
        Sheets("1").Select
        Cells(5, 8) = "=EOMONTH(R[-1]C,0)"
        days_month = Day(Cells(5, 8))
        
        Sheets("Summary").Select
                  
        Dim row_max As Long
              
         row_max = 14 + days_month
          
        Workbooks("B.xls").Worksheets("data").Range(Cells(1, 1), Cells(row_max, 1)) = ActiveSheet.Range(Cells(1, 2), Cells(row_max, 2))
    The code stops there and I can't make it work

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VBA code: run-time error 1004 (application-defined or object-defined error)

    Moved To Office Development
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,450

    Re: VBA code: run-time error 1004 (application-defined or object-defined error)

    Workbooks("B.xls").Worksheets("data").Range(Cells(1, 1), Cells(row_max, 1))
    as the cells are not fully qualified they refer to cells on the activesheet
    try like
    vb Code:
    1. with Workbooks("B.xls").Worksheets("data")
    2.                .Range(.Cells(1, 1), .Cells(row_max, 1)) = whatever
    3. end with
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    2

    Re: VBA code: run-time error 1004 (application-defined or object-defined error)

    Hi,

    Works fine - problem solved!

    Thanks!!!

  5. #5
    Junior Member
    Join Date
    Nov 2015
    Posts
    22

    Re: VBA code: run-time error 1004 (application-defined or object-defined error)

    Sub explicit()
    Set fnd = Range("a:a").Find("Br")
    If fnd Is Nothing Then Exit Sub
    Set first = fnd
    Set prev = fnd
    Do
    Set fnd = Range("a:a").Find("Br", fnd)
    If fnd Is Nothing Or fnd.Address = first.Address Then Exit Do
    If Left(fnd, 3) = "Br " Then
    Debug.Print fnd.Address
    rwcnt = fnd.Row - prev.Row
    fnd.Offset(-1).Resize(10 - rwcnt).EntireRow.Insert
    Set prev = fnd
    End If
    Loop
    End Sub
    error 1004 plz help

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width