outlawdevil
Board Regular
- Joined
- Jun 30, 2009
- Messages
- 238
I have a worksheet with data tab and upload tab. I want to create a macro that can copy the range of cell from the data tab based on critieria(Blue, Red, White).
I found this macro that almost does what I want but it is pasting critieria range into new sheets. I want everything to be pasted in to specific range of the upload tab. ( I want to reuse this macro everytime, is it possible that it will do a clear content each time when paste into the range?) Can anyone help me modify this macro? thanks. I have attached screenshot for your review as well.
I found this macro that almost does what I want but it is pasting critieria range into new sheets. I want everything to be pasted in to specific range of the upload tab. ( I want to reuse this macro everytime, is it possible that it will do a clear content each time when paste into the range?) Can anyone help me modify this macro? thanks. I have attached screenshot for your review as well.
VBA Code:
Sub filter()
Application.ScreenUpdating = False
Dim x As Range
Dim rng As Range
Dim last As Long
Dim sht As String
'specify sheet name in which the data is stored
sht = "Data Tab"
'change filter column in the following code
last = Sheets(sht).Cells(Rows.Count, "C").End(xlUp).Row
Set rng = Sheets(sht).Range("A1:C" & last)
Sheets(sht).Range("C1:C" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AA1"), Unique:=True
For Each x In Range([AA2], Cells(Rows.Count, "AA").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=3, Criteria1:=x.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
ActiveSheet.Paste
End With
Next x
' Turn off filter
Sheets(sht).AutoFilterMode = False
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub