+ Reply to Thread
Results 1 to 9 of 9

Loop to delete rows on another tab and run until blank cell is met.

Hybrid View

SillySox Loop to delete rows on... 02-11-2013, 09:47 PM
patel45 Re: Loop to delete rows on... 02-12-2013, 02:45 AM
Andrew-R Re: Loop to delete rows on... 02-12-2013, 03:55 AM
SillySox Re: Loop to delete rows on... 02-12-2013, 09:13 PM
Andrew-R Re: Loop to delete rows on... 02-13-2013, 03:26 AM
SillySox Re: Loop to delete rows on... 02-13-2013, 07:24 PM
SillySox Re: Loop to delete rows on... 02-13-2013, 07:30 PM
Andrew-R Re: Loop to delete rows on... 02-14-2013, 03:08 AM
SillySox Re: Loop to delete rows on... 02-14-2013, 11:09 PM
  1. #1
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Loop to delete rows on another tab and run until blank cell is met.

    Something like this - replace the sheet names and the columns with your own:

    Const sDATA_SHEET As String = "Sheet1"
    Const sSEARCH_SHEET As String = "Sheet2"
    Const sSEARCH_RANGE As String = "A:A"
    Const sSTART_RANGE As String = "A9"
    
    Dim rngLoop As Range
    Dim rngFind As Range
    
    Set rngLoop = Sheets(sDATA_SHEET).Range(sSTART_RANGE)
    
    While rngLoop.Value <> ""
      If rngLoop.Offset(0, 1).Value <> "" Then
        Set rngFind = Sheets(sSEARCH_SHEET).Range(sSEARCH_RANGE).Find(rngLoop.Offset(0, 1).Value, Lookin:=xlValues, LookAt:=xlWhole, MatchCase:=False)
        While Not rngFind Is Nothing
          rngFind.EntireRow.Delete
          Set rngFind = Sheets(sSEARCH_SHEET).Range(sSEARCH_RANGE).Find(rngLoop.Offset(0, 1).Value)
        Wend
      End If
      Set rngLoop = rngLoop.Offset(1)
    Wend

  2. #2
    Registered User
    Join Date
    02-10-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Loop to delete rows on another tab and run until blank cell is met.

    thanks Andrew! you truly are a legend!

    One final thing - the spreadsheet this is working on contains product lines that have had base codes changed for various reasons and this part of the spreadsheet was to remove/delete the codes that relate to the same items but were earlier codes. Your loop works very well - but we have found that we can have 4 or more codes that relate to the 'master' code in col "A"

    The data comes to us with the 'master' code in col "A" - old code 1 in "B", old code 2 in "C" and so on. How can I get this loop to run for codes in Col"B" in respect to "A" and then in col"C" in respect to "A" and so on.

    Apologies if I am being stupid here - but I am new to this.

    thanks for your help to date Andrew - it is HUGELY appreciated - I think by MANY MANY others on this site as well.

    cheers

    ps - I did try changing sSearchString from B:B to C:C thinking it was an easy answer but obviously not :-(
    Last edited by SillySox; 02-12-2013 at 09:17 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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