+ Reply to Thread
Results 1 to 6 of 6

Deleting partial row if certain value exists

  1. #1
    Registered User
    Join Date
    12-30-2014
    Location
    South Dakota, USA
    MS-Off Ver
    2003
    Posts
    2

    Deleting partial row if certain value exists

    Sorry in advance. I'm fairly new to VBA but diving in as far as I can. Have a couple of books I'm looking so I can ensure my foundational knowledge will be solid. Someday. I've looked and looked for my answer on my current project but I'm not finding it. So, alas I'm raising my hand for help. This seems like a great forum to do that on.

    So I have an excel sheet where I had to reformat and rename information to transfer data to another workbook. While my ultimate plan is to someday have the workbooks talk to each other and we won't be updating it manually at all, I'm taking smaller steps for now. So I thought I'd at least automate what I can so it really is just transferring data. I've gotten all of the other parts of the macro to work from formatting data to the pivot tables to get totals. There is one part I'm stumped on and that is deleting only a partial row and then shifting the data up.

    I have information in columns A - F and then again in I - N. I only want the data in cells A - F to move up if the value in the F column matches the word 'production'. I want all columns after F to stay put.

    Here is the coding I have so far. But I'm just not knowledgeable enough even through trial and error to fix this.

    Dim i As Long
    For i = Range("F" & Rows.Count).End(x1Up).Row To 1 Step -1
    If Range("F" & i).Value = "production" Then Range("A" & i).Resize(1, 6).delete Shift=x1Up
    Next i
    End Sub


    I'm getting a Run-time error '1004' that says Application-defined or object-defined error. It is showing that it is happening on the For statement.

    Any help anyone can give would be so greatly appreciated!!!

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Deleting partial row if certain value exists

    Please Login or Register  to view this content.
    Should do it, you were using Range instead of Cells
    If someone has helped you then please add to their Reputation

  3. #3
    Forum Contributor
    Join Date
    11-05-2013
    Location
    Germany
    MS-Off Ver
    Excel 2013
    Posts
    120

    Re: Deleting partial row if certain value exists

    Hi Emily and welcome to the forum,

    in general to get the best answers here start using the coding brackets around your code so its directly visible. It will look like this then

    Please Login or Register  to view this content.
    And by far the best method is always to make a new excel workbook with 2 sheets where you show before and how you would like to have it after + show the code you already have (only the part where you have problems.
    Say thanks, Click *

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Deleting partial row if certain value exists

    @pjwhitfield. Range will work just fine.

    Is this a 1 (number 1) instead of a l (letter l)?

    Please Login or Register  to view this content.
    It should be xlUp not x1Up
    Last edited by stnkynts; 01-02-2015 at 07:51 PM.

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Deleting partial row if certain value exists

    Try

    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  6. #6
    Registered User
    Join Date
    12-30-2014
    Location
    South Dakota, USA
    MS-Off Ver
    2003
    Posts
    2

    Re: Deleting partial row if certain value exists

    Thank you all!!! Great educational feedback. I'm back at it this morning and will give it a go.

+ 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] deleting partial row
    By jaunfra in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2013, 03:22 PM
  2. if partial data exists in one colum, copy to another column
    By Gunther in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-16-2011, 09:23 AM
  3. Deleting Partial Content in a Column
    By luu980 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-09-2009, 03:58 PM
  4. deleting partial data in column
    By joelw in forum Excel General
    Replies: 4
    Last Post: 10-07-2008, 12:05 PM
  5. Deleting a sheet if it exists?
    By drucey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-17-2006, 11:00 AM

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