Hi all,
i want to check unique records from specefic column and based on that criteria i want to paste all data from main sheet to other sheet.
pls check the code below and help me to fix this problem.
Private Sub test()
Dim i As Integer
Dim ClientName() As String
ClientName = StoreUniqueRecordsInArray
For i = 1 To rcount
Sheets("sheet1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:=ClientName(i) /error script out of range
Cells.Copy
Sheets.Add
ActiveSheet.Paste
ActiveSheet.Name = ClientName(i)
Sheets("sheet1").Select
Next i
End Sub
Function StoreUniqueRecordsInArray() As String()
Dim strNames() As String
Dim Uniques As New Collection
Dim ReqRange As Range
Set ReqRange = Range("B2:B10000")
rcount = 0
On Error Resume Next
For Each cell In ReqRange
Uniques.Add cell.Value, CStr(cell.Value)
Next cell
For Each Item In Uniques
rcount = rcount + 1
strNames(rcount) = Item
Next Item
StoreUniqueRecordsInArray = strNames
End Function
i want to check unique records from specefic column and based on that criteria i want to paste all data from main sheet to other sheet.
pls check the code below and help me to fix this problem.
Private Sub test()
Dim i As Integer
Dim ClientName() As String
ClientName = StoreUniqueRecordsInArray
For i = 1 To rcount
Sheets("sheet1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:=ClientName(i) /error script out of range
Cells.Copy
Sheets.Add
ActiveSheet.Paste
ActiveSheet.Name = ClientName(i)
Sheets("sheet1").Select
Next i
End Sub
Function StoreUniqueRecordsInArray() As String()
Dim strNames() As String
Dim Uniques As New Collection
Dim ReqRange As Range
Set ReqRange = Range("B2:B10000")
rcount = 0
On Error Resume Next
For Each cell In ReqRange
Uniques.Add cell.Value, CStr(cell.Value)
Next cell
For Each Item In Uniques
rcount = rcount + 1
strNames(rcount) = Item
Next Item
StoreUniqueRecordsInArray = strNames
End Function