emay 0 Newbie Poster

Hello,

I need to report frequencies of items from a source workbook & sheet to a target one. If the item already exists in the target, it should just add the count to the correct column, whereas if it doesn't exist, if sould had it to the end of the list and add the count to the correct collumn. Below is what i did, which doesn't work. Maybe you can help me !

Best wishes,
Emay

Sub SendData()
Dim Item As String
Dim Frequ As Long
Dim Group As String
Dim Subsect As Long
Dim CurRow As Long
Windows("Source.xls").Activate
Group = "Group5"
Subsection = 1

ActiveSheet.Range("A1:A50").Select

For Each Cell In Selection
CurRow = Cell.Row
    If Cell.Value <> "" Then
        Item = Cell.Value

        Frequ = Cell(Cell.Row, 2).Value
        Call AddData(Item, Frequ, Group, Subsect)
    End If
Next Cell

End Sub

Sub AddData(Item As String, Frequency As Long, SheetName As String, SubsectNr As Long)
Dim CurRow As Long
Dim MatchCount As Long
Dim NextRow As Long
Dim TargetCol As Long
MatchCount = 0
SubsectNr = 1

If SubsectNr = 1 Then TargetCol = 3
If SubsectNr = 2 Then TargetCol = 5
If SubsectNr = 3 Then TargetCol = 7
If SubsectNr = 4 Then TargetCol = 9
If SubsectNr = 5 Then TargetCol = 11
    Windows("Target.xls").Activate
    Sheets(SheetName).Activate
   
    ActiveSheet.Range("A10:A1000").Select
    
    For Each Cell In Selection
    CurRow = Cell.Row
        If Cell.Value = Item Then
            Cells(CurRow, TargetCol).Value = "X"
            MatchCount = MatchCount + 1
        End If
    Next Cell
    
    If MatchCount = 0 Then
        NextRow = Range("A65536").End(xlUp).Row + 1
        Cells(NextRow, 1).Value = Item
        Cells(NextRow, TargetCol).Value = Frequency
    End If

End Sub