TylerCross
New Member
- Joined
- Jan 5, 2021
- Messages
- 7
- Office Version
- 2010
- Platform
- Windows
Hello everyone who reads this,
I am currently stuck on how to complete this task. I currently coding a VLOOKUP macro. I am only needing to select a columns out of my data which are A, C ,K, V and W. Below I posted my code that I have, the highlighted section is where the problem is occurring. I have tried multiple things but I seem to not figure out. Any help is appreciated.
Sub Transfer()
Dim i As Long, j As Long, lastrow1 As Long, lastrow2 As Long
Dim myname As String
lastrow1 = Sheet1.Range("K" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow1
myname = Sheet1.Cells(i, "K").Value
Sheet3.Activate
lastrow2 = Sheet3.Range("D" & Rows.Count).End(xlUp).Row
For j = 2 To lastrow2
If Sheet3.Cells(j, "D").Value = myname Then
Sheet1.Activate
Sheet1.Union(Range(i, "A"), Range(i, "C"), Range(i, "K"), Range(i, "V"), Range(i, "W")).Copy
Sheet3.Activate
Sheet3.Range(Cells(j, "O"), Cells(j, "S")).Select
ActiveSheet.Paste
End If
Next j
Application.CutCopyMode = False
Next i
Sheet1.Activate
Sheet1.Range("A1").Select
-Tyler
End Sub
I am currently stuck on how to complete this task. I currently coding a VLOOKUP macro. I am only needing to select a columns out of my data which are A, C ,K, V and W. Below I posted my code that I have, the highlighted section is where the problem is occurring. I have tried multiple things but I seem to not figure out. Any help is appreciated.
Sub Transfer()
Dim i As Long, j As Long, lastrow1 As Long, lastrow2 As Long
Dim myname As String
lastrow1 = Sheet1.Range("K" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow1
myname = Sheet1.Cells(i, "K").Value
Sheet3.Activate
lastrow2 = Sheet3.Range("D" & Rows.Count).End(xlUp).Row
For j = 2 To lastrow2
If Sheet3.Cells(j, "D").Value = myname Then
Sheet1.Activate
Sheet1.Union(Range(i, "A"), Range(i, "C"), Range(i, "K"), Range(i, "V"), Range(i, "W")).Copy
Sheet3.Activate
Sheet3.Range(Cells(j, "O"), Cells(j, "S")).Select
ActiveSheet.Paste
End If
Next j
Application.CutCopyMode = False
Next i
Sheet1.Activate
Sheet1.Range("A1").Select
-Tyler
End Sub