Closed Thread
Results 1 to 2 of 2

run time error 1004 application-defined or object-defined error

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2015
    Location
    bulawayo,zimbabwe
    MS-Off Ver
    2013
    Posts
    3

    run time error 1004 application-defined or object-defined error

    sorry i am not experienced in VBA. I have 2 workbooks (saleman .xls and DailyReport.xlsm). Saleman .xls is generated by my POS daily by over writing the existing data in the file. DailyReport.xlsm has functions to generate reports using data copied from saleman .xls. I am trying make a vba script that will copy data from saleman .xls ( excluding headings) and paste to the last row of the table in sheet 1 of DailyReport.xlsm. i tried the code below and received thiS error message "run time error 1004 application-defined or object-defined error".
    Sub CopyReps_btn()
    
    Dim WS, WS2 As Worksheet
    Dim LastRow As Long
    'Dim lastCell As Range
    Dim LastCellRowNumber As Long
    Dim sPath As String, sFile As String
    
    
    Dim wb As Workbook, wb2 As Workbook
    Dim vFile As Variant
    
    'Set source workbook
    Set wb = ThisWorkbook
    Set wb = ActiveWorkbook
    Set WS = ActiveSheet
    With WS
        Set lastCell = .Cells(.Rows.Count, "C").End(xlUp)
        LastCellRowNumber = lastCell.Row + 1
    End With
    
    
    'Set selectedworkbook
    sPath = "C:\Sales2016APD\DownloadAPD\"
        sFile = sPath & "salesman.xls"
    Workbooks.Open (sFile)
    Set wb2 = ActiveWorkbook
    Set WS2 = wb2.Sheets("salesman")
    
    'last row
      With WS2
            LastRow = .Cells(.Rows.Count, A).End(xlUp).Row
    'Select cells to copy
    
    wb2.Worksheets("Output").Range("A2", "N" & LastRow).Select
    Selection.Copy
    End With
    'Go back to original workbook you want to paste into
    wb.Activate
    
    'Paste starting at the last empty row
    wb.Worksheets("DailyReport.xlsm").Range("C" & LastCellRowNumber).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    'Close and save the workbook you copied from
    wb2.Close
    
    End Sub

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: run time error 1004 application-defined or object-defined error

    Pls take some minutes to read forum rules, before you post again, because,unfortunately(this time..):

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  2. excel macro run time error '1004'- Application defined or object defined error
    By kmadan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2014, 09:51 AM
  3. [SOLVED] How to Debug-Run Time error- 1004 Application-Defined or object defined error
    By joyhampton in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2014, 05:37 PM
  4. Replies: 1
    Last Post: 03-12-2014, 12:42 PM
  5. [SOLVED] Run time error 1004 Application-Defined or Object-Defined Error - Placing data into next e
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-27-2014, 12:57 PM
  6. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  7. [SOLVED] run-time error '1004' application-defined or object-defined error - Excel 2007
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 02:46 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