Hello -
I need help creating a vba code. I input data from a database to an excel sheet. I would like to sort this data into different spreadsheets. For instance: I want to sort "ele" and "ele-c" and have those criteria go to sheet one. Then have data "insta" go to sheet two, etc. The data I don't care about could remain on the input sheet. This is the code I have now. I want to be able to send two different criteria to one page.
Sub NotificationSort()
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim SheetNames As Variant
Dim i As Long
Dim LR As Long
Set SourceSheet = Sheets("Data")
SheetNames = Array("ELE", "INSTA", "INSTF", "MW", "PFW")
Const FilterColumn = 6
With SourceSheet
LR = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 0 To UBound(SheetNames)
Set TargetSheet = Worksheets(SheetNames(i))
TargetSheet.Cells.ClearContents
With .Range("A1:H" & LR)
.AutoFilter Field:=FilterColumn, Criteria1:=SheetNames(i)
.Offset(0, 0).Copy TargetSheet.Range("A1")
End With
Next i
End With
End Sub
I need help creating a vba code. I input data from a database to an excel sheet. I would like to sort this data into different spreadsheets. For instance: I want to sort "ele" and "ele-c" and have those criteria go to sheet one. Then have data "insta" go to sheet two, etc. The data I don't care about could remain on the input sheet. This is the code I have now. I want to be able to send two different criteria to one page.
Sub NotificationSort()
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim SheetNames As Variant
Dim i As Long
Dim LR As Long
Set SourceSheet = Sheets("Data")
SheetNames = Array("ELE", "INSTA", "INSTF", "MW", "PFW")
Const FilterColumn = 6
With SourceSheet
LR = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 0 To UBound(SheetNames)
Set TargetSheet = Worksheets(SheetNames(i))
TargetSheet.Cells.ClearContents
With .Range("A1:H" & LR)
.AutoFilter Field:=FilterColumn, Criteria1:=SheetNames(i)
.Offset(0, 0).Copy TargetSheet.Range("A1")
End With
Next i
End With
End Sub