Run Time Error when running a VBA string to remove unique duplicates

妖精的绣舞 提交于 2021-01-29 10:20:56

问题


So I initially asked how to remove unique duplicates based on case sensitivity (please refer to the link below: Excel: Removing Duplicates Based On Case Sensitivity

and ultimately I was guided to the following link:

How to remove duplicates that are case SENSITIVE in Excel (for 100k records or more)?

This time I'm using column q to test out the formula and so far the following formula works:

Sub duptest()

Sheets("Analysis").Select

Dim x, dict
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
x = Range("Q1:Q100000" & lr).Value
Set dict = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(x, 1)
    dict.Item(x(i, 1)) = ""
Next i
Range("Q1:Q100000" & lr).ClearContents
Range("Q1").Resize(dict.Count).Value = Application.Transpose(dict.keys)


End Sub

My issue, however, is that I would prefer that the range be the entire column Q but when making the following change:

Sub duptest()

Sheets("Analysis").Select

Dim x, dict
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
x = Range("Q:Q" & lr).Value
Set dict = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(x, 1)
    dict.Item(x(i, 1)) = ""
Next i
Range("Q:Q" & lr).ClearContents
Range("Q1").Resize(dict.Count).Value = Application.Transpose(dict.keys)


End Sub

I get an error stating "Run-time error '1004': Method 'Range' of object '_Global' failed

I thought I would be cute and make the ranges "Q1:Q1000000" but I end up with the same error. Any advise would be appreciated. I do not wish for this to reflect on the entire workbook nor the worksheet, I would like for this to occur only for column Q.

apologies for the novice questions.

来源:https://stackoverflow.com/questions/63178074/run-time-error-when-running-a-vba-string-to-remove-unique-duplicates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!