In this article you will learn how to transfer the specific data form one sheet to another, through VBA in Microsoft Excel.
We have data in range A:G columns, in which column A contains Name, column B contains Address, column C contains city, column D region, column E country, column F phone number and column G contains criteria.
From this data, we want to extract those candidate’s data who are not eligible, which we can find out in column G. To transfer the specific data from one sheet to another sheet in a workbook follow below given steps:-
- Open VBA Page press the key Alt+F11
- Double Click on Workbook in the list of VBA project
- Then select workbook at the place of General
- Write the below mentioned code:-
Private Sub Workbook_Open() Dim i, Lastrow Lastrow = Sheets("Sheet1").Range("A" & Rows.count).End(xlUp).Row Sheets("Sheet2").Range("A2:I600").ClearContents For i = 2 To Lastrow If Sheets("Sheet1").Cells(i, "G").Value = "Not" Then Sheets("Sheet1").Cells(i, "G").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.count).End(xlUp).Offset(1) End If Next i End Sub
Code Explanation: First we have defined the variables, then we have given the definition of last row in the coding language of VBA, it will work for if data range is not decided than it will check last active range, and then will go in 2nd sheet and clear all the content from the sheet2. For i, we will define the range. And IF condition is used for define the condition, the data we want to pick and then paste in 2nd sheet.
- To run the code press F5
- Define data will get copied in the 2nd sheet
We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at [email protected]