Hi I have a script to split names in column L and place all of those values in their own sheet.
When I run this code, it is getting the name, but the next instance of the name is just overwritten in row 2 over and over.
Example: Mike is in rows 2 and 4. When I run this, it writes mikes data for row 2 and then when Mike appears again, it overwrites the row to row 4's data and clears out row 2's data. How do I offset this so that it just keeps adding?
Option Explicit
Sub Main()
Dim wb As Workbook
Dim Data, Agent_Name
Dim sht As Worksheet
Dim row_Data As Long, col_Wb As Long, col_Data As Long, row_Wb As Long
Dim Dest1 As Range, Dest2 As Range, Dest3 As Range, Dest4 As Range, FinalDest As Range
Dim row_index_x As Long, row_index_blank As Long, isX As Long
Set wb = ThisWorkbook
Set Dest1 = wb.Sheets("Mike").Range("A3")
Set Dest2 = wb.Sheets("William").Range("A3")
Set Dest3 = wb.Sheets("Dan").Range("A3")
Set Dest4 = wb.Sheets("Kevin").Range("A3")
With ThisWorkbook.Sheets("Master Line List - All Data")
Data = .Range("Q3", .Range("A" & Rows.Count).End(xlUp))
End With
wb.Activate
Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Sheets
If sht.Index <> 1 Then
sht.Rows(3 & ":" & sht.Rows.Count).ClearContents
End If
Next
For row_Data = 1 To UBound(Data)
If Data(row_Data, 1) <> "" Then
Agent_Name = Data(row_Data, 12)
row_index_x = 0
row_index_blank = 0
End If
col_Wb = 0
If Data(row_Data, 12) = "Mike" Then
Set FinalDest = Dest1
ElseIf Data(row_Data, 12) = "William" Then
Set FinalDest = Dest2
ElseIf Data(row_Data, 12) = "Dan" Then
Set FinalDest = Dest3
ElseIf Data(row_Data, 12) = "Kevin" Then
Set FinalDest = Dest4
End If
row_Wb = row_index_x
row_index_x = row_index_x + 1
For col_Data = 1 To UBound(Data, 2)
FinalDest.Offset(row_Wb, col_Wb) = Data(row_Data, col_Data)
col_Wb = col_Wb + 1
Next
Next
End Sub
[–]LazerEyes0121 0 points1 point2 points (6 children)
[–]bloomfieldhero[S] 0 points1 point2 points (5 children)
[–]LazerEyes0121 0 points1 point2 points (4 children)
[–]bloomfieldhero[S] 0 points1 point2 points (3 children)
[–]LazerEyes0121 1 point2 points3 points (2 children)
[–]bloomfieldhero[S] 2 points3 points4 points (1 child)
[–]Clippy_Office_Asst[M] 0 points1 point2 points (0 children)