Forum Discussion
WilderBog
Jul 02, 2019Copper Contributor
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...
- Jul 03, 2019
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 SubBest regards
Bernd
https://vba-tanker.com
Berndvbatanker
Jul 03, 2019Iron Contributor
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
WilderBog
Jul 03, 2019Copper Contributor
Exactly what I was looking for!
Thank you very much for this Bernd, that makes this process a great deal easier, now to apply your solution to my spreadsheet.