Hi all, I want to use VBA for excel to look for all values(ID) of Sheet1 (eg. image 1) column A which is located in Sheet2 (eg. image 2). Then I want it to copy the data of the 2 columns (eg. image 2) beside the value of Sheet2 into Sheet1's columns C and D (eg. image 3). The final product should look like image 3 which is in Sheet 1.
Hope someone is able to help me with this.
Below is the script that I have written but it doesn't work.
Sub ID()
Dim ID&, i&
Dim cell As Range
Dim arr(1 To 1000000, 1 To 2)
With Sheets("Sheet 1")
ID = .Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In .Range("A2:A" & ID)
If cell > 0 Then
i = i + 1
arr(i, 1) = cell
Selection.Copy
End If
Next
End With
Sheets("Sheet 2").Select
ActiveCell.Offset(0, -1).Columns("A:A").EntireColumn.Select
Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas2, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet 1").Cells(2, 3).Resize(i, 4).ActiveSheet.Paste
End Sub
Hope someone is able to help me with this.
Below is the script that I have written but it doesn't work.
Sub ID()
Dim ID&, i&
Dim cell As Range
Dim arr(1 To 1000000, 1 To 2)
With Sheets("Sheet 1")
ID = .Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In .Range("A2:A" & ID)
If cell > 0 Then
i = i + 1
arr(i, 1) = cell
Selection.Copy
End If
Next
End With
Sheets("Sheet 2").Select
ActiveCell.Offset(0, -1).Columns("A:A").EntireColumn.Select
Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas2, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet 1").Cells(2, 3).Resize(i, 4).ActiveSheet.Paste
End Sub