New to VB and a bit lost...
I have one workbook with two sheets. I need to Compare col A on each sheet. If the computer name in Sheet1 Col A finds a match on Sheet2 A:A then the macro will add a line in sheet2 and add then data from Sheet1 cols A,B then del the data from Sheet1.
Sheet1
A | B
|EVW7LT206152 | Hug,Aman
|WNW7LN000000 | Impo,MrsUn
|EVW7LT205803 | Doe,Jane
|EVW7LN205817 | Doe,John
Sheet2
A B C D
|EVW7LN205817| Doe,John | 12/20/2014 | 191.000.43.170
|EVW7LT206152| Hug,Aman | 12/20/2014 | 191.000.43.10
|NYW7LN000000| Impo,MrUn| 12/20/2014 | 191.000.43.197
|EVW7LT205803| Doe,Jane | 12/20/2014 | 191.000.43.145
Sheet1 (Finished)
A | B
WNW7LN000000 | Impo,MrsUn
Sheet2 (Finished)
A B C D
|EVW7LN205817 | Doe,John | 12/20/2014 | 191.000.43.170
|EVW7LN205817 | Doe,John | |
|EVW7LT206152 | Hug,Aman | | 191.000.43.10
|EVW7LT206152 | Hug,Aman | |
|NYW7LN000000| Impo,MrUn | 12/20/2014 | 191.000.43.197
|EVW7LT205803| Doe,Jane | | 191.000.43.145
|EVW7LT205803| Doe,Jane | |
This was close but does not del matches from sheet 1 like in my example.
Function DoOne(RowIndex As Integer) As Boolean
Dim Key
Dim Target
Dim Success
Success = False
If Not IsEmpty(Cells(RowIndex, 1).Value) Then
Key = Cells(RowIndex, 1).Value
Sheets("Sheet1").Select
Set Target = Columns(1).Find(Key, LookIn:=xlValues)
If Not Target Is Nothing Then
Rows(Target.Row).Select
Selection.Copy
Sheets("Sheet2").Select
Rows(RowIndex + 1).Select
Selection.Insert Shift:=xlDown
Rows(RowIndex + 2).Select
Application.CutCopyMode = True
Selection.Insert Shift:=xlDown, copyOrigin:=xlFormatFromLeftOrAbove
Cells(RowIndex + 3, 1).Select
Success = True
End If
End If
DoOne = Success
End Function
-
Sub TheMacro()
Dim RowIndex As Integer
Sheets("Sheet2").Select
RowIndex = Cells.Row
While DoOne(RowIndex)
RowIndex = RowIndex + 3
Wend
End Sub