02-12-20 03:00 PM
03-12-20 06:10 PM
Dim varData(2) As Object
varData(0) = "1"
varData(1) = "2"
ws.Range("A1:C100").RemoveDuplicates(Columns:=varData, Header:=2)
03-12-20 09:43 PM
Hi Nupur,
You can use the below code
Dim wb,ws, dup as object
try
wb= getworkbook(handle,workbook)
ws= getworksheet(handle,workbook, worksheet)
dup= ws.application.range(Input_Range).removeduplicates(columns:=1)
success= True
Catch e as exception
success = False
Message = e.message
Finally
wb=nothing
ws=nothing
dup=nothing
end try
You have to supply inputs for
1. Workbook as text
2. Worksheet as text
3. input_Range as text Eg. for full column it will be "B:B" for anything else "A1:B8"
4. handle as number
be mindful of the column number you are entering in the line
dup= ws.application.range(Input_Range).removeduplicates(columns:=1)
'here in this example its column A
1 refers to column A
2 refers to columns B
Good luck
04-12-20 12:20 PM
04-12-20 03:45 PM
Hello @NupurSood,
Do you want to remove the duplicates based on one specific column value or you wanted to compare the full rows and then remove the data?
Since the code stage will vary based on the requirement. Please confirm and i can share the code with you. :)
04-12-20 04:33 PM
04-12-20 05:13 PM
@NupurSood It seems to be a rather weird conflict between VBA and VB.NET. It doesn't help that the documentation for the Excel interop library is vague as well. What I've found is similar to what Susamay posted below. It seems if you pass in a single column index things work fine. Alternatively, you can pass in an array of indices if you know them ahead of time. Here are examples of both approaches that I've verified on my machine:
ws.Range(myRange).RemoveDuplicates(Columns:=New Object() {1, 2}, Header:=1)
or
ws.Range(myRange).RemoveDuplicates(1,1)
The first example shows how you could pass in an array of indices. I've tried pulling that array creation out and assigning it to an actual Object variable, but the same data type exception is thrown. Very weird. The second example shows passing in a single column index.
Cheers,
13-08-21 03:50 PM
13-08-21 04:09 PM
15-08-21 11:40 PM
16-08-21 07:32 AM