+ Reply to Thread
Results 1 to 5 of 5

Edit A Line to Include Variations

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2008
    Location
    New Jersey
    Posts
    52

    Edit A Line to Include Variations

    Hey guys,

    How would I edit the line
    If .Value <> "Public relations" Then .EntireRow.Delete
    to include more than one value?

    I have variations of "Public Relations" that include "Public relations;Attorneys" etc. and they get deleted when I run my macro..


    Sub PublicRelationsOnly()
    
        Dim Firstrow As Long
        Dim Lastrow As Long
        Dim Lrow As Long
        Dim CalcMode As Long
        Dim ViewMode As Long
    
        With Application
            CalcMode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
    
        With ActiveSheet
    
            .Select
    
            ViewMode = ActiveWindow.View
            ActiveWindow.View = xlNormalView
    
    
            .DisplayPageBreaks = False
    
            Firstrow = .UsedRange.Cells(1).Row
            Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
    
    
            For Lrow = Lastrow To Firstrow Step -1
    
    
                With .Cells(Lrow, "BC")
    
                    If Not IsError(.Value) Then
    
                        If .Value <> "Public relations" Then .EntireRow.Delete
    
    
                    End If
    
                End With
    
            Next Lrow
    
        End With
    
        ActiveWindow.View = ViewMode
        With Application
            .ScreenUpdating = True
            .Calculation = CalcMode
        End With
    
    End Sub
    I know its probably something simple, but I'm still pretty lost when it comes to this stuff..

    Thanks in advance

  2. #2
    Registered User
    Join Date
    08-10-2007
    Posts
    51
    Replace the following line:

    If .Value <> "Public relations" Then .EntireRow.Delete
    with this one instead:

    If left(.Cells(Lrow, "BC").Value, len("Public relations")) <> "Public relations" Then .EntireRow.Delete
    That will ignore anything with "Public relations" in it.

    You should optimize your code by using the find function and find all values where 'public relations' is found partly. Learn it up.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    It depends on exactly what the criteria is. If the words must be contained in the text in any case (upper, lower, mixed), then
    If InStr(1, .Text, "public relations", vbTextCompare) = 0 Then .EntireRow.Delete

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You might use the Like comparison
    If Not (LCase(.Value) Like "public*relation*") Then .EntireRow.Delete
    which will not delete "Public Relation Department", "Public relations expert" "PublicRelations typo" and other variations.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    07-08-2008
    Location
    New Jersey
    Posts
    52
    Thanks for all your help guys, it works great!

+ 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