Hello everyone, I have searched for this answer for an hour and a half now and have found threads treating this issue but all answers are customized to the specific question asker's needs and I can't figure out how to translate them to my needs. Here is my issue: I have a main sheet titled "AllDepts" which contains 20,000 rows. Column T specifies which department number each row belongs to, the whole sheet is sorted so that all of the same department numbers are grouped together. I need to copy all of the rows that have the same department number in column T to a new sheet. There are 20 different department numbers so I will end up with 20 different sheets that have isolated each department. Department 1 will go to sheet1, department 2 will go to sheet2 and so on. I have found a VBA that does this but it goes line by line and takes a long time to finish, is there any way to make this VBA more efficient so that it identifies the whole block of rows that have the same value in Column T and copies/pastes them in one swoop instead of going line by line? Here is the tediously slow VBA that I am currently using:
Sub DistDepts()
For Each Cell In Sheets(1).Range("T:T")
If Cell.Value = "1" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("Sheet1").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Sheets("AllDepts").Select
End If
Next
End Sub
Sub DistDepts()
For Each Cell In Sheets(1).Range("T:T")
If Cell.Value = "1" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("Sheet1").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Sheets("AllDepts").Select
End If
Next
End Sub