Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub whatever()
- Dim i As Long, a As Long
- Dim lngTopRowsToStartFrom As Long
- lngTopRowsToStartFrom = 2
- Dim objSheet As Worksheet
- Set objSheet = ActiveWorkbook.Sheets(1)
- Dim allCustomers() As String
- Dim bolInit As Boolean
- For i = lngTopRowsToStartFrom To Rows.Count
- If Trim(Range("B" & i).Value) <> "" Then
- If bolInit Then
- ReDim Preserve allCustomers(1 To UBound(allCustomers) + 1)
- Else
- ReDim allCustomers(1 To 1)
- bolInit = True
- End If
- allCustomers(UBound(allCustomers)) = Range("B" & i).Value
- End If
- Next i
- bolInit = False
- Dim uniqueCustomers() As String
- Dim bolAlreadyAdded As Boolean
- For i = 1 To UBound(allCustomers)
- If Not bolInit Then
- ReDim uniqueCustomers(1 To 1)
- uniqueCustomers(1) = allCustomers(1)
- bolInit = True
- Else
- bolAlreadyAdded = False
- For a = 1 To UBound(uniqueCustomers)
- If uniqueCustomers(a) = allCustomers(i) Then
- bolAlreadyAdded = True
- Exit For
- End If
- Next a
- If Not bolAlreadyAdded Then
- ReDim Preserve uniqueCustomers(1 To UBound(uniqueCustomers) + 1)
- uniqueCustomers(UBound(uniqueCustomers)) = allCustomers(i)
- End If
- End If
- Next i
- Dim objSheetToInsertAfter As Worksheet
- Dim objNewInsertedSheet As Worksheet
- Set objSheetToInsertAfter = objSheet
- Dim strSafeSheetName As String
- For i = 1 To UBound(uniqueCustomers)
- Set objNewInsertedSheet = ActiveWorkbook.Sheets.Add(, objSheetToInsertAfter)
- strSafeSheetName = Replace(uniqueCustomers(i), "/", "")
- strSafeSheetName = Replace(strSafeSheetName, "*", "")
- objNewInsertedSheet.Name = strSafeSheetName
- Set objSheetToInsertAfter = objNewInsertedSheet
- 'MsgBox "inserting new sheet: " & vbCrLf & uniqueCustomers(i)
- Next i
- objSheet.Activate
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement