Hi,
Background:
within the range H5-H1000 of the sheet ABC there are different or recurring statements.
With this unique values i want to start the following procedure:
1. take only the unique values out of this range; exclude empty-cells
2. within the current excel-document, the following tasks have to take place:
a) Sheets("ABC").Copy After:=Sheets(Variable)
b) Sheets("ABC (Variable)").Name = "Unique Value"
c) Selection.AutoFilter Field:=8, Criteria1:="Unique Value"
Description:
b = new sheets with sheet-labels of every unique value out of the already mentioned range
c = the value for "Criteria1" has to be the same name as the corresponding sheet-label. Task c has to be executed for every new sheet (except the sheet ABC)
Who can support me with the VB-Code for task 1, respectively the loop to complete tasks a-c ?
thanks in advance
Frank
Frank,
Assuming that cell H4 of sheet 'ABC' is a header for data in H5:H1000, you should be able to use the following:
Sub tgr() Dim rngDest As Range Dim arrUnq As Variant Dim arrIndex As Long Dim xlCalc As Integer Set rngDest = Cells(1, ActiveSheet.UsedRange.Column + ActiveSheet.UsedRange.Columns.Count + 1) With Application xlCalc = .Calculation .Calculation = xlCalculationManual .ScreenUpdating = False End With With Range("H4:H1000") .AutoFilter 1, "<>" .Copy rngDest .AutoFilter End With With Range(rngDest, rngDest.End(xlDown)) .AdvancedFilter xlFilterCopy, , .Offset(, 1), True arrUnq = Application.Transpose(Range(rngDest.Offset(1, 1), rngDest.Offset(, 1).End(xlDown)).Value) .Resize(, 2).EntireColumn.Delete End With For arrIndex = 1 To UBound(arrUnq) Sheets("ABC").Copy After:=Sheets(Sheets.Count) With ActiveSheet .Name = arrUnq(arrIndex) .UsedRange.AutoFilter 8, arrUnq(arrIndex) End With Next arrIndex With Application .Calculation = xlCalc .ScreenUpdating = True End With End Sub
Hope that helps,
~tigeravatar
Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks