+ Reply to Thread
Results 1 to 4 of 4

Modify existing code to act on multiple conditions

Hybrid View

MikeWaring Modify existing code to act... 06-26-2018, 02:07 PM
Fluff13 Re: Modify existing code to... 06-26-2018, 02:33 PM
MikeWaring Re: Modify existing code to... 06-26-2018, 02:47 PM
Fluff13 Re: Modify existing code to... 06-26-2018, 03:11 PM
  1. #1
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    Modify existing code to act on multiple conditions

    Here's another bit of help I need

    I have part of a macro that deletes certain rows of a spreadsheet, ie where it finds cells in col C in which the data starts with a "1" and deletes the whole row.

    I now need it to delete more rows, based on 2 more conditions, ie where the data in Col C starts with a "0" or a "2".

    I realise I could just copy / paste that code and change the "1" for a "0" and a "2", but I suspect there's a neater way of doing it (using two "or" commands?) I've had a play with it but I just get errors, or nothing

    Here's the current code:
    'Removes any rows with cell data in Col C beginning with "1" (these would be MTS Website shipments)
        Dim lngLastRow As Long, lngRow As Long
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
        End With
        lngLastRow = Range("A" & Rows.Count).End(xlUp).Row
        For lngRow = lngLastRow To 2 Step -1
        If Left(Range("C" & lngRow), 1) = "1" Then Rows(lngRow).Delete
        Next lngRow
        With Application
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
    I'm sure you guys / gals will have a simple solution!! LOL

    Kindest regards
    Mike

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,791

    Re: Modify existing code to act on multiple conditions

    If col C is values rather than formulae try
    Sub Delrws()
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
       With Range("C2", Range("A" & Rows.Count).End(xlUp).Offset(, 2))
          .Value = Evaluate(Replace("if((left(@,1)=""0"")+(left(@,1)=""1"")+(left(@,1)=""2""),true,@)", "@", .Address))
          .SpecialCells(xlConstants, xlLogical).EntireRow.Delete
       End With
    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
    End Sub

  3. #3
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    Re: Modify existing code to act on multiple conditions

    Hi, sorry - it works now...
    I just re-pasted it and all works perfectly

    thanks again for your help

    Kind regards
    mike

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,791

    Re: Modify existing code to act on multiple conditions

    Glad to help & thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Modify existing code to work with new workbook.
    By moonbreakker in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-14-2016, 12:03 PM
  2. Modify Existing VBA Code
    By jsolder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2016, 12:24 PM
  3. Need to modify Existing Code
    By missit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2016, 03:03 AM
  4. [SOLVED] Modify existing Code.
    By JO505 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-12-2014, 05:26 PM
  5. [SOLVED] Help modify existing Copy-Paste code
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2014, 10:03 AM
  6. [SOLVED] Modify Existing Mbr Code to Save to Ext.Workbook
    By Miskondukt in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 03-06-2013, 02:36 PM

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