+ Reply to Thread
Results 1 to 4 of 4

Macro to ckeck duplicated file name

Hybrid View

  1. #1
    Registered User
    Join Date
    09-16-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    11

    Macro to ckeck duplicated file name

    Hi!

    i'm trying to creat a macro that looks in column A and B. after that it check if column A have the same file name as B if not it will mart with the color red. and same with the B column.
    But i dosent work.

    
    Sub Kontroll()
        Dim Name1 As String
        Dim Name2 As String
        Dim iRow() As Integer
        Dim iRows() As Integer
        Dim i As Integer
        Dim j As Integer
        
        iRow = Sheets("Kontroll").Range("A2").CurrentRegion.Rows.Count
        iRows = Sheets("Kontroll").Range("B2").CurrentRegion.Rows.Count
        
        For i = LBound(iRow) To UBound(iRow)
            For j = LBound(iRows) To UBound(iRows)
                Name1 = Sheets("Controll").Range("A" & i).Value
                Name2 = Sheets("Controll").Range("B" & j).Value
                
                If Name1 <> Name2 Or Name2 <> Name1 Then
                    Sheets("Controll").Range.Range("A" & j).Interior.Color = 255
                End If
            Next j
        Next i
    End Sub
    thx in advance
    Last edited by newapa; 09-26-2012 at 10:31 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to ckeck duplicated file name

    Sub Kontroll()
        Dim Name1 As String
        Dim Name2 As String
        Dim iRow As Range
        Dim iRows As Range
        Dim i As Integer
        Dim j As Integer
        
        Set iRow = Range("A2").CurrentRegion.Resize(, 1)
        iRow.Select
        Set iRows = Range("A2").CurrentRegion.Offset(0, 1).Resize(, 1)
        iRows.Select
        For i = 1 To iRow.Rows.Count
            For j = 1 To iRows.Rows.Count
                Name1 = iRow(i, 1).Value
                Name2 = iRows(j, 1).Value
                If Name1 = Name2 Then
                    iRows(j, 1).Interior.Color = 255
                End If
            Next j
        Next i
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to ckeck duplicated file name

    Hi, newapa,

    the start of the loop is set to row 2 of Column A and only checks one column versus the other (alternative would be WorksheetFunction.Countif):
    Sub Kontroll()
        Dim i As Integer
        Dim var As Variant
        
        For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
          var = Application.Match(Cells(i, 1).Value, Columns(2), 0)
          If Not IsError(var) Then
             Cells(i, "A").Interior.Color = 255
    '         Cells(var, "B").Interior.Color = 255
          End If
        Next i
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to ckeck duplicated file name

    ottimo codice ! veramente compatto.

+ 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