Hi guys,
I have a problem with the following code in VBA. I'm very new to VBA, so I can't see what seems to be the problem.... The followin code gives me Run-time error 1004 autofilter method of range class failed....
I really appreciate the help you can give me!
THANKS!
I have a problem with the following code in VBA. I'm very new to VBA, so I can't see what seems to be the problem.... The followin code gives me Run-time error 1004 autofilter method of range class failed....
Rich (BB code):
Sub SplitData()
Dim ark As Worksheet
Dim arkNew As Worksheet
Dim Data As Range
Dim rfll As Range
Dim Rum As String
Set ark = ThisWorkbook.Sheets("Alle Rum")
With ark
Set Data = .Range(.Cells(1, 1), .Cells(.Rows.Count, 9).End(xlUp))
.Columns(.Columns.Count).Clear
.Range(.Cells(3, 6), .Cells(.Rows.Count, 6).End(xlUp)).AdvancedFilter Action:=xlFilterCopy, copyToRange:=.Cells(1, .Columns.Count), unique:=True
For Each rfll In .Range(.Cells(1, .Columns.Count), .Cells(.Rows.Count, .Columns.Count).End(xlUp))
Rum = rfll.Text
If WksExists(Rum) Then
Sheets(Rum).Cells.Clear
Else
Set arkNew = Sheets.Add
arkNew.Move After:=Worksheets(Worksheets.Count)
arkNew.Name = Rum
End If
Data.AutoFilter Field:=6, Criteria1:=Rum IT'S HERE THE ERROR IS!
Data.Copy Destination:=Worksheets(Rum).Cells(1, 1)
Next rfll
End With
ark.Columns(Columns.Count).ClearContents
Data.AutoFilter
End Sub
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
THANKS!
Last edited by a moderator: