Results 1 to 9 of 9

Locate column with specific title and delete rows if predefined set of text is found

Threaded View

  1. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Locate column with specific title and delete rows if predefined set of text is found

    Hi, johnny_tc,

    I used an With...End With and referred to the sheet within the (no need for the sheet to be activates).

    You select the sheet so any information on Rows, Columns, cells, Ranges is lost. That´s the reason for your run time error.

    If you want to go on with
    Sheets("Raw Data").Select
    just add the line directly beneath that line of Code
    With ActiveSheet
    and leave everything else as it was.

    Or you have a go with
    Sub DeletePublicationType()
    
    Dim lngCounter As Long
    Dim lngLastRow As Long
    Dim rngFound As Range
    Const cstrSEARCH As String = "Publication Type"
    
    Sheets("Raw Data").Select
    Set rngFound = Rows("1:1").Find(what:=cstrSEARCH, _
        LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns)
    If Not rngFound Is Nothing Then
      lngLastRow = Cells(Rows.Count, rngFound.Column).End(xlUp).Row
      For lngCounter = lngLastRow To 2 Step -1
        Select Case (Cells(lngCounter, rngFound.Column).Value)
          Case "Country Business Guide", "Country HR Web Guide", "Country Guide", "Country Snapshot", "Business Guide"
            Rows(lngCounter).Delete
          Case Else
            'keep record
        End Select
      Next lngCounter
    End If
    
    Set rngFound = Nothing
    
    End Sub
    Ciao,
    Holger
    Last edited by HaHoBe; 08-23-2012 at 07:18 AM. Reason: maybe better explanation

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