+ Reply to Thread
Results 1 to 6 of 6

Skipping a blank cell and checking next cell in a column

  1. #1
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    213

    Skipping a blank cell and checking next cell in a column

    Hi,
    Hopefully someone can help. I currently have a code for a macro that searches a column to see if there are any duplicates found in that column after it is sorted. It then highlights the cell red and continues to search for duplicates. It runs until the cell is empty because the row number is unknown. I want to know how can i modify the following code to continue doing the necessary function but it comes across a blank cell to skip it and try the next cell in that column. If it comes across 3 empty cells in a row then it should terminate the process and move on. Any help is greatly appreciated I posted a few times the last few days and this is my last step needed. Thank You!

    Sub FindDups ()
    '
    ' NOTE: You must select the first cell in the column and
    ' make sure that the column is sorted before running this macro
    '
    ScreenUpdating = False
    FirstItem = ActiveCell.Value
    SecondItem = ActiveCell.Offset(1, 0).Value
    Offsetcount = 1
    Do While ActiveCell <> ""
    'Matches firstitem with second item if they match turn red and move onto next cell
    If FirstItem = SecondItem Then
    ActiveCell.Offset(Offsetcount,0).Interior.Color = RGB(255,0,0)
    Offsetcount = Offsetcount + 1
    SecondItem = ActiveCell.Offset(Offsetcount, 0).Value
    Else
    ActiveCell.Offset(Offsetcount, 0).Select
    FirstItem = ActiveCell.Value
    SecondItem = ActiveCell.Offset(1,0).Value
    Offsetcount = 1
    End If
    Loop
    ScreenUpdating = True
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Skipping a blank cell and checking next cell in a column

    You say your data are sorted. Excel sorting moves any blank cells to the bottom of the sort list.

    But you seem to say you still have blanks in that list which you want to skip.

    Could you please clarify, alternatively post a sample file showing just what you're trying to do?

  3. #3
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Skipping a blank cell and checking next cell in a column

    It's Sorted by column A which has all file numbers and no blank cells. It is then sorted by column C which sometimes has blank cells. I would post some examples but unfortunately I'm not near that computer with the file. Hope this helps.

    Quote Originally Posted by kalak View Post
    You say your data are sorted. Excel sorting moves any blank cells to the bottom of the sort list.

    But you seem to say you still have blanks in that list which you want to skip.

    Could you please clarify, alternatively post a sample file showing just what you're trying to do?

  4. #4
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Skipping a blank cell and checking next cell in a column

    Quote Originally Posted by trevor2524 View Post
    ...

    ' NOTE: You must select the first cell in the column and
    ' make sure that the column is sorted before running this macro
    ...
    There seems nothing about any other column referred to in your code.

    If your NOTE above is correct you won't have blanks in that column until after the end of the non-blank cells.

    Without an illustration, or better explanation ... ??

  5. #5
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Skipping a blank cell and checking next cell in a column

    The active column code and the sorting code are done before this macro is called that is why I left them off. So when this macro is called upon the sorting is already done first by column A then by Column C. Column C is the column this macro is running through and the one I need help figuring out how to skip over an empty cell. Like i orginally posted. Any suggestions would be helpful on how to modify my current code to do this task.

    Quote Originally Posted by kalak View Post
    There seems nothing about any other column referred to in your code.

    If your NOTE above is correct you won't have blanks in that column until after the end of the non-blank cells.

    Without an illustration, or better explanation ... ??

  6. #6
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Skipping a blank cell and checking next cell in a column

    change your line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

+ 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