Jerry Sullivan
MrExcel MVP
- Joined
- Mar 18, 2010
- Messages
- 8,787
Hi all,
I'm stumped on this one and haven't been able to find the answer through search.
This comes from the macro-recorder when I remove duplicates from the last 3 columns of my range.
I want to make a macro that does this using variables instead of Array(3, 4, 5)
but I get an error when trying to pass an array built from variables.
I've tried Integer, Long and Variant data types, but no luck.
Thanks in advance.
I'm stumped on this one and haven't been able to find the answer through search.
This comes from the macro-recorder when I remove duplicates from the last 3 columns of my range.
Rich (BB code):
Sub Macro1()
' Macro1 Macro
Range("A1:E8").Select
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$E$8").RemoveDuplicates _
Columns:=Array(3, 4, 5), Header:=xlYes
End Sub
I want to make a macro that does this using variables instead of Array(3, 4, 5)
but I get an error when trying to pass an array built from variables.
Rich (BB code):
Sub MyTry1()
Dim iArray() As Integer, i As Integer
With ActiveSheet.Range("$A$1:$E$8")
ReDim iArray(1 To .Columns.Count - 2)
For i = 1 To 3
iArray(i) = i + 2
Next i 'Result is iArray= (3, 4, 5)
.RemoveDuplicates Columns:=iArray, Header:=xlYes
'returns Run-time error "5": Invalid procedure call or argument
End With
End Sub
I've tried Integer, Long and Variant data types, but no luck.
Thanks in advance.