+ Reply to Thread
Results 1 to 2 of 2

VBA Code to delete from row 2 based on 2 criteria

  1. #1
    Registered User
    Join Date
    03-01-2015
    Location
    Northants
    MS-Off Ver
    2007
    Posts
    15

    VBA Code to delete from row 2 based on 2 criteria

    Hi All

    I cannot get my head around this one.

    I need to copy everything in a worksheet after row 1 (as it contains headers) from one worksheet to another (say CSVin to CSVout). I only to copy rows from CSVin where two criteria are met:

    - Column 'A' starts with the letter 'C' (customer codes start with 'C', supplier codes start with 'S' - I only want customers).
    - Column 'D' does NOT start with the word 'ERROR' (I only want non-error rows).

    I have managed to do this with only one criteria (column 'D' does not start with the word 'ERROR'), using the following filter criteria.

    wsErrors.Cells.ClearContents
    ' Set Filter for Range to Copy (column 4 does not start with 'Error')
    rngToCopy.AutoFilter Field:=4, Criteria1:="<>ERROR*", Field:=1, Criteria2:="C*"


    ' Copy text only to worksheet wsOut (CSVOut)
    rngToCopy.SpecialCells(xlCellTypeVisible).Copy wsOut.Range("A1")

    But I cannot work out how to put in a second criteria based on a second column in the row.

    Can anyone help with this please?

    Many thanks

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA Code to delete from row 2 based on 2 criteria

    Use one autofilter line if the two criteria are applied to one column. Otherwise, use an autofiter line for each column you want to filter.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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: 1
    Last Post: 12-09-2015, 01:24 PM
  2. [SOLVED] VB Code to Delete value of cell if criteria is met
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-14-2015, 11:44 AM
  3. Delete columns & Row based on criteria VBA code needed
    By Gary B in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-28-2014, 02:59 PM
  4. Code troubles - Trying to copy a row to another sheet based on criteria, then delete
    By kurt1985 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-21-2014, 10:48 AM
  5. [SOLVED] Code to delete row when certain criteria met
    By midoop in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-03-2013, 05:52 PM
  6. Code to delete rows based on status code in Column I
    By LemonTwist in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2009, 07:01 PM

Tags for this Thread

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