[英]Range.DisplayFormat method and VBA Excel 2007
I want to check if there are any duplicates in my column, I set a conditional formatting manually and then I made the following test : 我想检查列中是否有重复项,手动设置条件格式,然后进行以下测试:
If cell2.DisplayFormat.Interior.Color <> RGB(255, 199, 206) Then
Label8.Caption = cell2.Offset(, 2).Text
Label9.Caption = cell2.Offset(, 3).Text
Label10.Caption = cell2.Offset(, 4).Text
Label12.Caption = cell2.Offset(, 5).Text
Label13.Caption = cell2.Offset(, 6).Text
Label28.Caption = cell2.Offset(, 7).Text
Label30.Caption = cell2.Offset(, 8).Text
CommandButton2.Enabled = True
Else
cell2.Value = ""
MsgBox "Votre bac existe déjà", vbExclamation, "Bac double"
Me.TextBox1.Value = ""
Me.TextBox1.SetFocus
End If
The problem is that I use Excel 2007, and this one does not support Range.DisplayFormat
method, so what I need is one of the following : 问题是我使用的是Excel 2007,并且此版本不支持
Range.DisplayFormat
方法,因此我需要以下内容之一:
Range.DisplayFormat
method. Range.DisplayFormat
方法的替代方法。 OR THANK YOU! 谢谢!
You can use the inbuilt conditional formatting functionality 您可以使用内置的条件格式设置功能
Either 要么
1) select the area to highlight and then go to Home > Conditional Formatting > Highlight cell rules > Duplicate Values
and choose your format 1)选择要突出显示的区域,然后转到“
Home > Conditional Formatting > Highlight cell rules > Duplicate Values
然后选择格式
Or 要么
2) Use code similar to the following: 2)使用类似于以下代码:
Sub findDupsInMyCol()
Dim wb As Workbook
Dim ws As Worksheet
Dim rngSelection As Range
Dim lastRow As Long
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Data")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row 'find last used row number
Set rngSelection = ws.Range("A1:A" & lastRow) 'set target range
ws.Activate
FormatDups rngSelection
End Sub
Sub FormatDups(ByRef rngSelected As Range)
rngSelected.FormatConditions.AddUniqueValues
rngSelected.FormatConditions(rngSelected.FormatConditions.Count).SetFirstPriority
With rngSelected.FormatConditions(1)
.DupeUnique = xlDuplicate
.Font.Color = -16383844
.Interior.PatternColorIndex = xlAutomatic
.Interior.Color = 13551615
.StopIfTrue = False
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.