2010-01-29 58 views

回答

2

您不需要VBA宏。您可以使用條件格式。微軟解釋如何做你似乎正是在這裏需要:

http://office.microsoft.com/en-us/excel/HA011366161033.aspx

如果你真的需要一個宏,最簡單的方法是將記錄上述步驟,然後根據需要進行修改。

+1

斷開的鏈接。你能更新嗎? – avgvstvs 2016-12-02 21:19:27

1

也許這片段是有用的:

Public Sub MarkDuplicates() 
Dim iWarnColor As Integer 
Dim rng As Range 
Dim rngCell As Variant 


Set rng = Range("A1:A200") ' area to check ' 
iWarnColor = xlThemeColorAccent2 

For Each rngCell In rng.Cells 
    vVal = rngCell.Text 
    If (WorksheetFunction.CountIf(rng, vVal) = 1) Then 
     rngCell.Interior.Pattern = xlNone 
    Else 
     rngCell.Interior.ColorIndex = iWarnColor 
    End If 
Next rngCell 
End Sub 
0
Sub MarkDuplicates2() 
Dim rngCell As Variant 
Dim flag As Integer 

Dim LastRow As Long 

'To Check Duplicate records for dynamic rows: 
    LastRow = 0 
    With ActiveSheet 
    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row 
    End With 

flag = 0`enter code here` 
'Cell(2,2) represent "B2" 
Set rng = Range(Cells(2, 2), Cells(LastRow, 2)) 
iWarnColor = xlThemeColorAccent2 

For Each rngCell In rng.Cells 
    vVal = rngCell.Text 
    If (WorksheetFunction.CountIf(rng, vVal) = 1) Then 
     rngCell.Interior.Pattern = xlNone 

    Else 
     rngCell.Interior.ColorIndex = iWarnColor 
     flag = flag + 1 
    End If 
Next rngCell 

    If flag > 0 Then 
    MsgBox flag & " cells (in light blue) contain an error. Please Check!" 
    Else 
    MsgBox " Data Validation completed. No errors found." 
    End If 

End Sub 
0
Sub Macro1() 

    Dim Counter As Integer 

    For Counter = 1 To 35 

     'Cells.(X,Y) X = number, Y = Letter i.e D5 Cells(5,4) 
     firstValue = ActiveSheet.Cells(Counter, 3) 
     SecondValue = ActiveSheet.Cells(Counter, 4) 

     If firstValue = SecondValue Then 
      Rows(Counter).Interior.Color = RGB(255, 10, 10) 
     End If 


    Next 

End Sub 
0

羅斯拉爾森回答了這個問題在這裏:Finding duplicate rows in excel

從他的回答引用,「絕對速度最快,最簡單的方法條件格式,突出顯示重複項(在ID列上),然後通過着色(在複選框上方)過濾列(可能在表格中)。「

昨天,我親自試過了這一點,它的工作太棒了。不需要編寫宏或者花哨的VBA腳本。只需使用Excel即用即用功能。

答案保羅雷納給在2010年有一個破碎的鏈接。羅斯拉森鏈接仍在工作 - 至少現在。

+0

@avgvstvs我把這個答案放在你的慫恿之中;) – keepaustinbeard 2017-06-07 16:28:06

+0

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的基本部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – mmichael 2017-06-07 16:54:10

+0

好的,我編輯了我的答案。這個好嗎? – keepaustinbeard 2017-06-08 17:41:00

相關問題