+ Reply to Thread
Results 1 to 7 of 7

Find a value and delete rows

  1. #1
    Forum Contributor
    Join Date
    05-06-2004
    Posts
    117

    Find a value and delete rows

    Hello to all and thank you in advance. I am trying to find the word "Mkt" within a sheet. I then would like to come down 2 cells and run a loop to match the value of a "Market" variable. If the cells donot match this value I would like to delete the row. The code works until I get to the code line " Set rngCurrentCell = Range(strColumnRange)" I get an 1004 error with the forllowing -(Method 'Range' of object'_Global' failed). Can anyone help?
    Please Login or Register  to view this content.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Where are you setting the Market variable? Is there more than one cell containing mkt?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    05-06-2004
    Posts
    117
    Hi RoyUK,
    the value for the "Market" variable comes from a cell in another tab. It can either be "night" or "day". Also, I believe that there is only one instance of the work "Mkt" in the Data sheet. Does this help?
    Thank you

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I'm not sure exactly what you want, but try this code & post back
    Please Login or Register  to view this content.
    Last edited by royUK; 10-08-2008 at 05:51 AM.

  5. #5
    Forum Contributor
    Join Date
    05-06-2004
    Posts
    117
    Hello RoyUK,

    I have taken the code that you provided. Thank you for your work. However, I am getting 2 compile errors. The first tells me "End With without With" and the second shows "For without Next". Also, to help some more, the variable "Market" is a named cell in another tab. So what I am trying to do is that when the named cell "Market" is "night", the macro would find the work "Mkt" in the Data sheet, go down 2 rows and if any cell does not say "night", delete the row. Does this help?
    Thank you for your continued help

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-06-2004
    Posts
    117
    Hello RoyUK,
    Thank you for getting back to me working on this. The code you reposted works.. However, I was wandering if you could tell me how it actually works.You see, the code deletes rows, but it stops short of where it should stop. In my data set, i have all of the rows with the word "day" in column G. So, theoretically, all my rows up to the word "Mkt" should be deleted right? (I set my "Market" variable to be "night"). This is not happening... only a few rows are deleted. I have checked my data set to make sure that the word "night" does not appear in column G (making the macro stop short). I did not find any instance of it. What do you think I am missing?
    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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