Forum Discussion

WilderBog's avatar
WilderBog
Copper Contributor
Jul 02, 2019
Solved

Copy Data to Other Sheets' Columns Based on Values

Hi All,   I have been searching like crazy but struggling to find a solution that specifically fits what I am aiming to achieve.   First week of every month, I hope to walk into a patch-cycle mee...
  • Berndvbatanker's avatar
    Jul 03, 2019

    WilderBog 

    Hi,

    you can do this with the following macro, see attachment.

     

    Sub TransferData()
    Dim lngRow As Long
    Dim lngRowmax As Long
    Dim rngFind As Range
    Dim lngRowMaxT As Long

    Sheet2.Range("A2:X" & Sheet2.Rows.Count).Clear

    With Sheet1
    lngRowmax = .Range("a" & .Rows.Count).End(xlUp).Row

    For lngRow = 1 To lngRowmax

    Set rngFind = Sheet2.Rows(1).Find(what:=.Range("A" & lngRow).Value, lookat:=xlWhole)
    If Not rngFind Is Nothing Then
    lngRowMaxT = Sheet2.Cells(Sheet2.Rows.Count, rngFind.Column).End(xlUp).Row + 1
    Sheet2.Cells(lngRowMaxT, rngFind.Column).Value = .Range("B" & lngRow).Value

    End If
    Next lngRow

    End With

    End Sub

     

    Best regards

    Bernd

    https://vba-tanker.com

Resources