VBA Script for AutoFill based on matching criteria

  • Hello everybody,

    I'm new to VBA and need some help with building a script which will :

    • Search for a match in the column if he finds a match sort it one row below and copies several cells from him.
    • If there is no match, do nothing.

    Here are more details :
    This is how looks my table :

    [ATTACH=JSON]{"alt":"Click image for larger version Name:\timage_71933.jpg Views:\t1 Size:\t40.7 KB ID:\t1201860","data-align":"none","data-attachmentid":"1201860","data-size":"custom","height":"514","width":"1065"}[/ATTACH]

    My goal is : When somebody enters new data in column B below row 4 ( SKU ) and there is a match the new data will be placed one row below and will be copied details from columns C, F, I, J from the matching data and on column H will be placed 0 on the duplicated rows.

    So far I was able to place the duplicates one below other with that script :

    Private Sub Worksheet_Change(ByVal Target As Range)
        On Error Resume Next
        If Not Intersect(Target, Range("B:B")) Is Nothing Then
            Range("B5").Sort Key1:=Range("B6"), _
              Order1:=xlAscending, Header:=xlYes, _
              OrderCustom:=1, MatchCase:=False, _
        End If
    End Sub

    If somebody can help me with the formula for vlookup and coping the data on the matching rows will be great.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!