+ Reply to Thread
Results 1 to 6 of 6

Deleting Unwanted rows

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Deleting Unwanted rows

    I am trying to create a macro that will scan through a particular column within the Raw data Import worksheet which may be really long (up to 7,000 rows) and delete any rows that do not have the sample name of Initial or does not contain "week" in the name and bring this data over to the reformat page. I have created a formula within the sample name in the reformat page that looks for the word "Initial" and adds a "0-" in front of it. If that can be added in the macro it would be great!!!! I only need to bring over the columns indicated in the reformat page.

    Stuck and need help
    Isara-NJ
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Deleting Unwanted rows

    You have not provided enough information.

    What Column are we to look at?
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Deleting Unwanted rows

    Sorry I thought I explained everything. Within the Raw Data Import sheet you are looking at the Sample Name column. There, any value that doesn't have to word "Initial" or contains the word "week" in the name is to be deleted. Once you have that final list, I need the Sample Name, Vial, Vial ID, Retention & Area columns to go over into the Reformat Data sheet. Before the Sample Name gets placed there I would need to look through the Sample name again and any row with the Sample Name of "Initial" I want to add a prefix of "0-" to the front of it. Hopefully this explains better what I need. Thank you so much for your help and please let me know if you need any further information.

    Thanks,
    Isara-NJ

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this demonstration !


    PHP Code: 
    Sub Demo1()
              Const 
    14"Reformat Data"
                
    Dim Rg As RangeL&
        
    With Worksheets("Raw Data Import").UsedRange.Resize(, C)
                   
    = .Rows.Count
                
    If 1 Then Beep: Exit Sub
                Application
    .ScreenUpdating False
                
    .Cells(2C).Resize(1).Formula "=(B2<>""INITIAL"")+ISERR(SEARCH("" week "",B2))=2"
                
    .Sort .Cells(C), xlAscendingHeader:=xlYes
                Set Rg 
    = .Columns(C).Find(True, , xlValues)
             If 
    Not Rg Is Nothing Then
              
    .Rows(Rg.Row ":" L).Clear
                Set Rg 
    Nothing
             End 
    If
                .
    Columns(C).Clear
                
    .AdvancedFilter xlFilterCopy, , Worksheets(D).UsedRange.Rows(1)
        
    End With
                Worksheets
    (D).UsedRange.Columns(1).Replace "INITIAL""0-INITIAL"xlWhole
                Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-06-2017 at 08:16 PM. Reason: optimization …

  5. #5
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Thumbs up Re: Deleting Unwanted rows

    Hi and thank you sooo much!!!
    It works great. Is it possible for you to send me an explanation of what it all means? I was going through the code trying to figure out how it works and can't even get how did you pick the right columns to copy over.

    Const C=14 is this the entire range to be worked on?
    L& what is that? I think it's the range of rows to be worked on but why did you need to add& to it?
    So you name the entire range with the next statement, then say if there's only one row then beep and exit. Why Beep?
    Set the screen to not flicker while processing.
    After that I'm not sure what is happening but think this is where you are deleting the rows that don't meet the criteria.
    Then you do the copy/paste of the data but not sure how you picked the correct columns.
    After that you change the naming of Initial and update the screen.

    If you can fill in the blanks for me to better understand I would greatly appreciate it. I'm trying to learn so if I ever need to adjust this in some way I know what I need to do and go to make the changes.

    Thank you soo much.
    Isara-NJ

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    When you like a code, show it by clicking on post bottom left star Add Reputation, thanks !

    C constant is just the column number where formula stands for marking rows to delete …

    L variable is for worksheet last row used,
    the sign & is a character to declare its type as you can read in VBA inner help of Long type.
    If last row is row #1 so there is nothing to do what's the beep warns
    and this test avoids an execution error under with the Resize statement …

    As deleting row by row is slower than clearing a single rows block the reason of using a sort.
    As Excel inner features are often faster than any code looping row by row !

    There is not a Copy/Paste but again an Excel basics feature :
    an advanced filter which picks up data according to result worksheet columns headers.

    Notice you can get same result worksheet without deleting anything in source worksheet
    just directly using an advanced filter with half of codelines !
    Last edited by Marc L; 04-07-2017 at 02:52 PM.

+ 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. [SOLVED] Filtering and deleting unwanted rows
    By joshag in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-25-2014, 01:59 PM
  2. [SOLVED] Deleting rows with unwanted data
    By gpowell in forum Excel General
    Replies: 2
    Last Post: 12-06-2013, 05:25 PM
  3. Deleting Unwanted Rows
    By Covenite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2012, 12:25 PM
  4. Deleting unwanted rows <10
    By reggie1000 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-25-2009, 11:21 AM
  5. Deleting unwanted rows
    By kevinho in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-19-2007, 05:25 PM
  6. Deleting unwanted and empty rows....
    By Jim in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-05-2005, 01:05 AM
  7. Deleting unwanted and empty rows...
    By Jim in forum Excel General
    Replies: 2
    Last Post: 07-04-2005, 07:05 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