Hi ,
I am very new to VBA Coding .I am trying to write a macro to move the data across the sheets in a workbook .
There are two sheets Active and Resignees. When I enter the ID in Resignees sheet (Cell D1 ) it should search the ID in Active sheet (Sheet having complete headcount details ) and return me with certain columns only .
Please help me with the correction for the below code .
I have tried a code :
Sub Button38_Click()
Dim i As Long
With ThisWorkbook.Worksheets("Resigned Employees")
If (ThisWorkbook.Worksheets("Resigned Employees").Range("D1").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "A")) Then
For i = 2 To ThisWorkbook.Worksheets("Active Employee").Cells(.Rows.Count, "A").End(xlUp).Row
If Not IsEmpty(.Cells(i, "A").Value) Then
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "A").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "A").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "B").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "B").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "C").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "C").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "D").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "D").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "E").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "H").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "F").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AG").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "G").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AI").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "H").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AJ").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "I").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AK").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "J").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AL").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "K").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AM").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "L").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AN").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "M").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AO").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "N").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "BH").Value
Else
MsgBox "Not Found!"
End If
End If
Next i
End With
MsgBox "Entry Completed"
End Sub
Thanks in Advance .
I am very new to VBA Coding .I am trying to write a macro to move the data across the sheets in a workbook .
There are two sheets Active and Resignees. When I enter the ID in Resignees sheet (Cell D1 ) it should search the ID in Active sheet (Sheet having complete headcount details ) and return me with certain columns only .
Please help me with the correction for the below code .
I have tried a code :
Sub Button38_Click()
Dim i As Long
With ThisWorkbook.Worksheets("Resigned Employees")
If (ThisWorkbook.Worksheets("Resigned Employees").Range("D1").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "A")) Then
For i = 2 To ThisWorkbook.Worksheets("Active Employee").Cells(.Rows.Count, "A").End(xlUp).Row
If Not IsEmpty(.Cells(i, "A").Value) Then
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "A").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "A").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "B").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "B").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "C").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "C").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "D").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "D").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "E").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "H").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "F").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AG").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "G").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AI").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "H").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AJ").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "I").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AK").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "J").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AL").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "K").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AM").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "L").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AN").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "M").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "AO").Value
ThisWorkbook.Worksheets("Resigned Employees").Cells(i, "N").Value = ThisWorkbook.Worksheets("Active Employee").Cells(i, "BH").Value
Else
MsgBox "Not Found!"
End If
End If
Next i
End With
MsgBox "Entry Completed"
End Sub
Thanks in Advance .