我正在尝试删除重复项而不弄乱边框。我已经编写了一些代码,但是当我尝试使用它时,它会弄乱边框或清除超出其范围的数据。
我只想比较我拥有的图纸列表,而不会超出指定范围或弄乱边框
Sub DelDupl()
Dim rng As Range
Set rng = Range("A13:F305")
Range("A13").CurrentRegion.RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes
With rng.Borders
.LineStyle = xlContinuous
.Color = vbBlack
.Weight = xlThin
End With
End Sub
我想将文档标识符列与工作表列进行比较,如果有匹配项,则删除相应的行。
答案 0 :(得分:1)
Sub Program1()
Dim wb As Workbook
Dim ws As Worksheet
Dim Rng As Range
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1")
With Sheets("Sheet1")
Lastrow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
End With
' for B column and C Column
Set Rng = ws.Range(ws.Cells(14, 2), ws.Cells(Lastrow, 3))
Rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlNo
End Sub
答案 1 :(得分:0)
我不确定您的RemoveDuplicates为什么基于C和D列,但是您需要摆脱CurrentRegion并定义范围。
With Range(Cells(13, "A"), Cells(rows.Count, "A").end(xlup))
.resize(.rows.count, 6).RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes
End With
'depending on what is below row 37, the range might have to be defined this way (although the former is preferable)
With Range(Cells(13, "A"), Cells(13, "A").end(xldown))
.resize(.rows.count, 6).RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes
End With
CurrentRegion是一个“数据岛”,它向各个方向延伸,直到遇到完全空白的列,完全空白的行或工作表的范围。位于A13周围的“数字岛”至少延伸到图像中的第8行。
可以通过选择一个单元格并点击Ctrl + A一次来测试CurrentRegion。