PDA

View Full Version : Subscript out of range



rabers
05-11-2012, 02:41 AM
hi,
i have a function called: "ColumnsToUse" and it goes like this:
Function ColumnsToUse()
.
.
Dim StaticColumnArray() As Integer
ReDim StaticColumnArray(1 To Length) As Integer
.
bla bla bla
.
.
ColumnsToUse = StaticColumnArray
End Function

and I also has a function to remove duplicates from a range called: "AllData"
Sub Button1_Click()
ActiveSheet.Range("AllData").RemoveDuplicates ColumnsToUse(), Header:=xlYes
End Sub

* the ColumnsToUse is an integer array.
the Function itself works well and ColumnsToUse holds the desired array.
but at the Button1 Sub i get: "Subscript out of range"
any idea why?
please assist
thanks
Rabers

Bob Phillips
05-11-2012, 03:00 AM
Don't you need some value in CoolumnsToUse?

rabers
05-11-2012, 03:34 AM
no.
the function just populate an array.
running just the Function end with "ColumnsToUse" holding the array with the desired items in it.
the Sub (Button1_Click) should operate the "removeDuplicates" of Excel for the range "AllData" where the titles of the range (thats indicate the columns to check for duplications) are being held at the ColumnsToUse" array

Bob Phillips
05-11-2012, 03:59 AM
Not tried t, but I would have thought it should just be

Sub Button1_Click()
ActiveSheet.Range("AllData").RemoveDuplicates Header:=xlYes
End Sub

rabers
05-11-2012, 06:00 AM
That's not the solution...
Though now the exception doesn't pops but nothing happens.
It can't be the solution since the part: "ColumnsToUse()" acctually uses the the Function which calculates the array.
As far as I understood- the RemoveDuplicate get its "arguments" from that Function.
Any other idea maybe?

rabers
05-13-2012, 12:29 PM
please...anyone?
i'm desperate...