Excel VBA - RemoveDuplicates方法不适用于Mac [英] Excel VBA - RemoveDuplicates method does not work with Mac

查看:321
本文介绍了Excel VBA - RemoveDuplicates方法不适用于Mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码,通过查看两列(第3列和第5列)来从工作表中删除重复项。

I have below piece of code to remove duplicates from a sheet by looking into two columns (column 3 & 5).

lRow = .Cells(Rows.Count, "A").End(xlUp).Row
'.Range("A1:BR" & lRow).RemoveDuplicates Columns:=Array(3, 5), Header:=xlYes
.Range("$A$1:$BR$" & lRow).RemoveDuplicates Columns:=Array(3, 5), Header:=xlYes

它在Windows中工作正常,但不幸的是不在Mac上。

It works fine in Windows but unfortunately not on Mac.

我在这里需要改变什么?

Can anybody please suggest me what do I need to change here?

推荐答案

这段代码将创建一个唯一值的列表,并复制到另一个单元格。所以创建唯一的列表。

This piece of code will create a list of unique values and copy into another cell. So create unique list.

您必须指定列表开始的位置,以及要复制到的位置。您可以通过更改fromCell和toCell变量来实现。我希望这有帮助。

You have to specify where your list starts, and where you want to copy to. You can do this by changing the fromCell and toCell variables. I hope this helps.

Sub uniqueList()

Sub uniqueList()

fromCell = "A1"
toCell = "B1"

fromColumn = Mid(fromCell, 1, 1) 'This will resolve to A
toColumn = Mid(toCell, 1, 1)     'This will resolve to B

fromRow = Mid(fromCell, 2)       'This will resolve to 1
toRow = Mid(toCell, 2)           'This will resolve to 1


Dim cl As Range, UniqueValues As New Collection, uValue As Variant
Application.Volatile

numRows = Range(fromCell).End(xlDown).Row

On Error Resume Next
For Each cl In Range(fromCell & ":" & fromColumn & numRows)
    UniqueValues.Add cl.Value, CStr(cl.Value)
Next cl

y = toRow - 1

For Each uValue In UniqueValues
    y = y + 1
    Range(toColumn & y) = uValue
Next uValue

End Sub

这篇关于Excel VBA - RemoveDuplicates方法不适用于Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆