+ Reply to Thread
Results 1 to 3 of 3

Loop through cells and then through all worksheets

Hybrid View

jeffreybrown Loop through cells and then... 01-30-2010, 03:37 PM
DonkeyOte Re: Loop through cells and... 01-30-2010, 03:49 PM
jeffreybrown Re: Loop through cells and... 01-30-2010, 04:21 PM
  1. #1
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Loop through cells and then through all worksheets

    Not sure what is missing here, but this will only highlight duplicates on the active sheet and won't cycle thru all worksheets in the workbook.

    Sub FindDups()
    Dim i As Range
    Dim ws As Worksheet
        For Each ws In ActiveWorkbook.Worksheets
            For Each i In Range("A1:E3")
                If Application.WorksheetFunction.CountIf(Range("A1:E3"), i) > 1 Then
                    i.Interior.ColorIndex = 33
                End If
            Next i
        Next ws
    End Sub
    Last edited by jeffreybrown; 01-31-2010 at 04:12 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Loop through cells and then through all worksheets

    You need to qualify the Range being iterated as belonging to the Worksheet object being iterated (eg ws), ie:

    For Each i In ws.Range("A1:E3")
    (same would hold true in the COUNTIF)

    You may however prefer to use a With statement...

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Loop through cells and then through all worksheets

    Quote Originally Posted by DonkeyOte View Post
    You may however prefer to use a With statement...
    Thanks Luke...As usual spot on...

    I'm not quite sure what you mean by the With statement, but would it have advantages over the ws.range?

+ 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