+ Reply to Thread
Results 1 to 2 of 2

having trouble with macro run time error 1004:

  1. #1
    Registered User
    Join Date
    06-18-2015
    Location
    california
    MS-Off Ver
    2013
    Posts
    0

    having trouble with macro run time error 1004:

    Hi All,
    I am having some trouble with the following code , there run time error 1004: is right where it says WSZ.Select

    can anyone tell me what is wrong?


    Sub DeleteNoVendors()

    Dim WSZ As Worksheet
    Dim EndRow4 As Long
    Dim LastRow As Long

    EndRow4 = Worksheets("CRM Data").Range("B" & Rows.Count).End(xlUp).Row
    LastRow = Worksheets("CRM Data").Cells(Rows.Count, 1).End(xlUp).Row

    Set WSZ = Worksheets("CRM Data")

    WSZ.Select
    WSZ.Range("A1") = "Property-HOA ID"
    WSZ.Range("B1") = "Property ID"
    WSZ.Range("E1") = "Vendor ID"
    WSZ.Range("G1") = "Payment Amount"
    WSZ.Range("H1") = "Payment Terms"
    WSZ.Range("J1") = "Invoice Edit"
    WSZ.Range("K1") = "Inv#"


    WSZ.Range("J2") = "=IF(LEFT(E2,1)="" "",RIGHT(E2,LEN(E2)-1),E2)"
    WSZ.Range("J2").Copy
    WSZ.Range("J3:J" & EndRow4).Select
    WSZ.Paste

    WSZ.Range("K2").Value = "=IF(LEFT(E2,2)=""V0"",E2,""Delete"")"
    WSZ.Range("K2").Copy
    WSZ.Range("K3:K" & EndRow4).Select
    WSZ.Paste

    WSZ.UsedRange.Value = WSZ.UsedRange.Value

    WSZ.Range("K2:K" & EndRow4).Copy
    WSZ.Range("E2:E" & EndRow4).Select
    WSZ.Paste

    With WSZ
    .AutoFilterMode = False
    With Range("A1:K" & LastRow) '--Assuming your header is in Row 2 and records start at Row 3.
    .AutoFilter Field:=5, Criteria1:="Delete" '--Field:=3 is Column C if data starts at A
    .Cells.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete '--Delete the visible ones.
    End With
    End With

    WSZ.AutoFilterMode = False


    Application.CutCopyMode = False

    End Sub

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166
    Hello evazar,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 10-20-2014, 05:33 PM
  2. [SOLVED] Sort Macro Run-time error '1004': Application/Object-defined error.
    By sam1212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2014, 10:05 AM
  3. Excel Macro Error - Run time error 1004 - Paste method of worksheet class failed
    By kvflynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2012, 10:51 AM
  4. Run-time error '1004': Macro error, only when shared
    By Pergo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2011, 12:57 PM
  5. Excel 2007 : Macro run-time error 1004
    By tuph in forum Excel General
    Replies: 4
    Last Post: 11-23-2009, 07:04 PM

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