Identify cells for deletion

  • Hi. Struggling with a little problem. In my program I choose a particular cell and double click it. this activates the sub which in turn deletes the complete row. That is exactly what it was designed to do, but now I've added a feature to the program which is housed to the right of the cells that are to be deleted. Since it is deleting the complete row, it messes up my new feature. Below is the portion of code:

    X is the cell in column 'A' that is activated.

    I need it to delete only the cells in row x from column 'A' to 'L' then shift:=xlUp

    Any help will be greatly appreciated

    Thanks

    JimmyB


    Code
    With Target
                x = Application.Match(.Value, Sheets("VALUES for MEALS").Range("A1:A1000"), 0)
            If Not IsError(x) Then Sheets("VALUES for MEALS").Rows(x & ":" & x).Delete Shift:=xlUp
        End With

    Thanks for your help

    JimmyB


    Some plans fail on execution

    All plans fail without

    8)

  • If you double click on a cell in the row to delete why use Match?


    Is x declared as a Long?


    You don't need a With statement in that snippet of code.

  • Hi Roy. Thanks for your quick reply.

    I did receive the code from someone at Ozgrid and tailored it to fit my requirement of deletion. I'm sure that my adaptations of the code is rudimentary at best, but I made it work. (and it worked perfectly for what I needed). An array would probably condense the length of the code, but I'm not sure how to proceed with that. I've included the full sub below. If you do take the time to help, please take note that I only want to delete up to column "L" (my initial request)

    Thanks again and have a great day :)

    Any help will be appreciated


    Thanks for your help

    JimmyB


    Some plans fail on execution

    All plans fail without

    8)

  • Maybe


    Code
    With Target
    x = Application.Match(.Value, Sheets("VALUES for MEALS").Range("A1:A1000"), 0)
    If Not IsError(x) Then Sheets("VALUES for MEALS").Range("A" & x & ":L" & x).Delete Shift:=xlUp
    End With


    But you don't need multiple with statements



    If the value is on the same row in all sheets then it could be further simplified

  • Using an array possibly


  • Awesome job Roy.

    The code to change my deletion from Row to specific range was bang on. I also streamlined my 'with' statements as you've suggested, with success. Tomorrow I'll streamline it even further with your recommendation to use the array in the above code. I can also adapt the array syntax in a few other areas of my program. Great job.

    Very much appreciate the help...all of it quite useful


    BTW... No the row numbers are not the same. Each sheet is sorted to different columns. Calorie sheet sorted to amount of calories on each food item (lowest to highest), TransFat sorted to amount of transfat (lowest to highest)...an so on. So the rows of food items are all over the map.


    It's 2am here. soooo g'nite


    Thanks again Roy

    JimmyB

    Thanks for your help

    JimmyB


    Some plans fail on execution

    All plans fail without

    8)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!