+ Reply to Thread
Results 1 to 3 of 3

Runtime error 1004

Hybrid View

  1. #1
    Registered User
    Join Date
    03-20-2009
    Location
    holon
    MS-Off Ver
    Excel 2003
    Posts
    18

    Runtime error 1004

    This code work just fine
    Private Sub FormatDate_Click()
    '===================================================================================================
    'FormatDate
    '===================================================================================================
    Dim Archive_Date, x As Variant
     Dim CellDate As String
     Set Archive_Date = Workbooks("Archives.XLS").Sheets("ArchiveDoc").Range("D2", Range("D" & Rows.Count).End(xlUp))
         For Each x In Archive_Date
                  CellDate = x.Value
                x.Value = Format(CellDate, "DD.MM.YYYY")
        
          Next x
       
    End Sub
    But if i put another set for other file i get run time error

    Private Sub CopyData_Click()
    '===================================================================================================
    'Copy Column From Payment_File to Archive_File
    '===================================================================================================
    Dim PaymentOrderBase, Archive_Invoice As Range
    Dim x As Variant, y As Variant
    Dim OrderPayment As String
    Dim OrderArchive, F As String
    
    Dim wb As Workbook
    Set wb = _
    Workbooks.Open("H:\Motorup\MotorUp-150409\Warranty\Payment\Test\PaymentReport.xls")
    'wb.Activate
    
    Set PaymentOrderBase = Workbooks("PaymentReport.XLS").Sheets("PaymentDoc").Range("B2", Range("B" & Rows.Count).End(xlUp))
    '============================================
    'for Archive_Invoice Set i get an error 1004
    '============================================
    Set Archive_Invoice = Workbooks("Archives.XLS").Sheets("ArchiveDoc").Range("C2", Range("C" & Rows.Count).End(xlUp))
    
      For Each x In PaymentOrderBase
           For Each y In Archive_Invoice
                 'Compare between invoices And Orders in Archive_File and Payment_File
              OrderPayment = Left(x.Offset(0, -1), 6)
             ' OrderArchive = y.Offset(0, -1)
               
               If x = y And OrderPayment = OrderArchive Then
         
                        
                 'Copy invoices from invoice column b:3 to column h:3
              y.Offset(0, 6) = x
                 'copy order column from Payment_File to Archive_File
               y.Offset(0, 5) = x.Offset(0, -1)
                  'copy Payment column from Payment_File to Archive_File
               y.Offset(0, 3) = x.Offset(0, 3)
                  'copy type column from Payment_File to Archive_File
               y.Offset(0, 7) = x.Offset(0, 4)
              End If
                     
            Next y
       Next x
    End Sub

    what is the problem?

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Runtime error 1004

    Hi michael1963,

    Change the following line of code...

    Set Archive_Invoice = Workbooks("Archives.XLS").Sheets("ArchiveDoc").Range("C2", Range("C" & Rows.Count).End(xlUp))
    ...to this:

    Set Archive_Invoice = Workbooks("Book1").Sheets("Sheet1").Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row)
    You can verify the range being set is correct by putting the following line of code immediately beneath the above line of code:

    MsgBox Archive_Invoice.Address
    I'd also do this for the "PaymentOrderBase" variable as it surprises me that this is returning the correct range either (I could be wrong).

    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    03-20-2009
    Location
    holon
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Runtime error 1004

    Thanks a lot its work

+ 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