Consulting

Results 1 to 4 of 4

Thread: run time error 1004 Pastespecial method of range class failed

  1. #1

    run time error 1004 Pastespecial method of range class failed

    please help me on this
    pastespecial method of range class failed
    run time error 1004


    Sub Show_Sale_Purchase_Data()
    
    Dim dsh As Worksheet
    Dim sh As Worksheet
    
    Set dsh = ThisWorkbook.Sheets("Sale_Purchase")
    Set sh = ThisWorkbook.Sheets("Sale_Purchase_Display")
    
    
    dsh.AutoFilterMode = False
    
    dsh.Range("H:H").NumberFormat = "dd-mm-yyyy"
    
    
    '''''''''Put filter here''''''
    
    dsh.UsedRange.AutoFilter 8, ">=" & Me.txt_Start_Date.Value, xlAnd, "<=" & Me.txt_End_Date.Value
    
    If Me.OptionButton3.Value = True Then
    
        dsh.UsedRange.AutoFilter 3, "Purchase"
    End If
    
    If Me.OptionButton2.Value = True Then
        dsh.UsedRange.AutoFilter 2, "Sale"
    End If
    
    sh.UsedRange.Clear
    
    dsh.UsedRange.Copy
    sh.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
    
    dsh.AutoFilterMode = False
    
    '''''''''Display Data in Listbox'''''''
    
     Dim lr As Long
     lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))
     
     If lr = 1 Then lr = 2
     
    With Me.ListBox2
        .ColumnCount = 8
        .ColumnHeads = True
        .ColumnWidths = "30,100,50,50,50,50,50,50"
        .RowSource = sh.Name & "!A2:H" & lr
        
    End With
    
    End Sub
    Attached Files Attached Files

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    :
    Try
    dsh.Cells.SpecialCells(xlCellTypeVisible).Copy
    sh.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    I agree with SamT to limit the copy area. I was going to suggest coding the specific range. UsedRange includes any cell on the sheet that may have been used or have format changes made ever. Copying/pasting that whole area might cause a crash for whatever reason. Beyond that, maybe it's just a syntax thing? Dave

  4. #4
    thanks very much for the directions

Posting Permissions

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