I am trying to automate a sheet I will get twice a month. Basically, it is sorted by a category, which is a singular letter. I have it able to sort the first table of data into separate sheets based on the category. However, I have a separate table of data I want to also sort into the already made sheets based on the same categories but into a new column, preferably with a blank column in between. Below is the code I found somewhere and I was going to just try and edit it to add the second table of data to a different column.
For clarification I get a table of data from two different programs. The first table the below works and creates new sheets within the workbook and lists all data with that same category in it. I want the second table to go into the sheets as well but in column C instead of column A.
Example data:
Table 1:
A 122
S 134
D 122
Table 2:
A 134
S 154
D 879
Code:
Sub Copy_Data()
Dim r As Range, LastRow As Long, ws As Worksheet
Dim LastRow1 As Long, MyColumn As String
Dim LastColumn As Long
Dim src As Worksheet
'Change this column Letter to the one with the Co ID in
MyColumn = "A"
'Change the worksheet name to the one with the data on
Set src = Sheets("CalAmp")
LastRow = src.Cells(Cells.Rows.Count, MyColumn).End(xlUp).Row
For Each r In src.Range(MyColumn & "2:" & MyColumn & LastRow)
On Error Resume Next
Set ws = Sheets(CStr(r.Value))
On Error GoTo 0
If ws Is Nothing Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = CStr(r.Value)
'This row adds a header from the soyrce sheet
'remove the ' if you want to do that
'src.Rows(1).Copy ActiveSheet.Range("A1")
LastRow1 = Sheets(CStr(r.Value)).Cells(Cells.Rows.Count, MyColumn).End(xlUp).Row
src.Rows(r.Row).Copy Sheets(CStr(r.Value)).Cells(LastRow1 + 1, 1)
Set ws = Nothing
Else
' Find the last row in the target sheet for the Co ID sheet
LastRow1 = Sheets(CStr(r.Value)).Cells(Cells.Rows.Count, MyColumn).End(xlUp).Row
' Find the next available column in the target sheet
LastColumn = Sheets(CStr(r.Value)).Cells(1, Sheets(CStr(r.Value)).Columns.Count).End(xlToLeft).Column + 1
' Reset the worksheet variable for the next iteration
Set ws = Nothing
End If
Next r
End Sub
A. What does "... into a new column..." mean? Are you copying only the values from columnAso that they could be copied, e.g., to columnC("... preferably with a blank column in between...")? Please clarify by editing your post.