(Solved) – want to match the values and if the value matches it one of the columns should get pasted in next empty cell. Below is my code

(solved)-–-want-to-match-the-values-and-if-the-value-matches-it-one-of-the-columns-should-get-pasted-in-next-empty-cell.-below-is-my-code
Sub business_segment()
        Dim erow As Long
        Dim lastrow As Longerow = Sheets("Placemat-business Segment").Cells(Rows.Count, 1).End(xlUp).Row
        erow1 = Sheets("Placemat-Busniess Segment").Cells(Rows.Count, 4).End(xlUp).Row
        erow2 = Sheets("Placemat-business Segment").Cells(Rows.Count, 5).End(xlUp).Row
        erow3 = Sheets("Placemat-business Segment").Cells(Rows.Count, 6).End(xlUp).Row
        erow4 = Sheets("Placemat-business Segment").Cells(Rows.Count, 7).End(xlUp).Row
        lastrow = Sheets("Actual").Cells(Rows.Count, 1).End(xlUp).Row
        For i = 4 To erow
           For r = 2 To lastrow
        If Sheets("Actual").Cells(r, 9) = Sheets("Placemat-business Segment").Cells(i, 3) And Sheets("Actual").Cells(r, 10) =
    Sheets("Placemat-business Segment").Range("D3") Then
        Sheets("Actual").Cells(r, 31).Copy
        Sheets("Actual").Paste Destination:=Sheets("Placemat-business Segment").Cells(erow, 4)
        ElseIf Sheets("Actual").Cells(r, 9) = Sheets("Placemat-business Segment").Cells(i, 3) And Sheets("Actual").Cells(r, 10) =
    Sheets("Placemat-business Segment").Range("E3") Then
        Sheets("Actual").Cells(r, 31).Copy
                        Sheets("Actual").Paste Destination:=Sheets("Placemat-business Segment").Cells(erow, 5)
        ElseIf Sheets("Actual").Cells(r, 9) = Sheets("Placemat-business Segment").Cells(i, 3) And Sheets("Actual").Cells(r, 10) =
    Sheets("Placemat-business Segment").Range("F3") Then
        Sheets("Actual").Cells(r, 31).Copy
        Sheets("Actual").Paste Destination:=Sheets("Placemat-business Segment").Cells(erow, 6)
        ElseIf Sheets("Actual").Cells(r, 9) = Sheets("Placemat-business Segment").Cells(i, 3) And Sheets("Actual").Cells(r, 10) =
    Sheets("Placemat-business Segment").Range("G3") Then
        Sheets("Actual").Cells(r, 31).Copy
        Sheets("Actual").Paste Destination:=Sheets("Placemat-business Segment").Cells(erow, 7)
        End If
        Next r
        Sheets("Placemat-business Segment").Activate
        Next i
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *