+ Reply to Thread
Results 1 to 10 of 10

Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

Hybrid View

JHric Correcting Syntax on For Loop... 09-26-2014, 12:18 PM
AB33 Re: Correcting Syntax on For... 09-26-2014, 12:21 PM
judgeh59 Re: Correcting Syntax on For... 09-26-2014, 12:22 PM
judgeh59 Re: Correcting Syntax on For... 09-26-2014, 12:23 PM
AB33 Re: Correcting Syntax on For... 09-26-2014, 12:32 PM
judgeh59 Re: Correcting Syntax on For... 09-26-2014, 12:37 PM
AB33 Re: Correcting Syntax on For... 09-26-2014, 12:43 PM
JHric Re: Correcting Syntax on For... 09-30-2014, 10:15 AM
JHric Re: Correcting Syntax on For... 09-26-2014, 12:39 PM
AB33 Re: Correcting Syntax on For... 09-26-2014, 12:40 PM
  1. #1
    Registered User
    Join Date
    09-04-2014
    Location
    Voorhees, New Jersey
    MS-Off Ver
    Microsoft 2010
    Posts
    8

    Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    I am trying to use a for loop to delete conditionally formatted duplicates, but I keep getting an error on the "End If". Can someone review this code to see what can replace the "End If" with correct syntax to makes the for loop operational?


    Sub sbDelete_Rows_Based_On_Cell_Color()
    Dim lRow As Long
    Dim iCntr As Long
    lRow = 14090
    For iCntr = lRow To 1 Step -1
    If Cells(iCntr, 1).Interior.ColorIndex = 3 Then ‘3=Red
    Rows(iCntr).Delete
    End If
    Next
    End Sub

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    Please use code tags with your code.

    Sub sbDelete_Rows_Based_On_Cell_Color()
    Dim lRow As Long
    Dim iCntr As Long
    lRow = 14090
    For iCntr = lRow To 1 Step -1
       If Cells(iCntr, 1).Interior.ColorIndex = 3 Then '‘3 = Red
         Rows(iCntr).Delete
       End If
    Next
    End Sub

  3. #3
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    try removing the

    " `=Red"

    the ` is not used for the comments if that is what you are trying do...the single quote ' is what you want....
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    @AB33 --- the guru's type faster than the experts....

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    judgeh,
    No really!
    I have only added a comment to the line.
    I think you are right, the OP meant to use a hyphen, not a comma.

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    AB33 - I thought the OP was trying the comment the 3=Red part and used the wrong character, I didn't think about make that part of the equation....actually, now I'm not sure what the OP was really trying to do with the 3=Red part...but I do know that the ` was causing the END IF error....

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    As far as I know, if the cell colour is formatted with conditional formatting, you can not evaluate the cell. In other words, the cell will not return true.

  8. #8
    Registered User
    Join Date
    09-04-2014
    Location
    Voorhees, New Jersey
    MS-Off Ver
    Microsoft 2010
    Posts
    8

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    @Ab33, Do you have any other ideas or solved solutions I can look at. If worst comes to worst, I could color coding the values (ex. #3 for red) in an addition column, then sorting them. The last step would be mass deleting the conditionally formatted cells by highlighting the entire block.

  9. #9
    Registered User
    Join Date
    09-04-2014
    Location
    Voorhees, New Jersey
    MS-Off Ver
    Microsoft 2010
    Posts
    8

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    It removed the End If Error, but no dice on the deleting.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Correcting Syntax on For Loop used to delete contionally highlighted duplicates.

    judgeh,
    The error is on the construction of if statement.

    If Cells(iCntr, 1).Interior.ColorIndex = 3 Then ‘3=Red

+ 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. Macro to find duplicates, concatenate cells, then delete old duplicates
    By givemepuppies in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 03-04-2016, 02:43 AM
  2. [SOLVED] Loop and delete duplicates
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2013, 02:16 PM
  3. [SOLVED] Macro to find duplicates, concatenate Unique Values, then delete old duplicates
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 04:32 PM
  4. Replies: 17
    Last Post: 07-05-2011, 05:37 PM
  5. How to delete rows when List toolbar's "delete" isnt highlighted?
    By Linda in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-26-2005, 05:15 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