A macro in excel

Closed
mishrarameswar Posts 2 Registration date Tuesday December 29, 2015 Status Member Last seen December 29, 2015 - Dec 29, 2015 at 03:10 AM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Dec 29, 2015 at 06:55 PM
Issue :
I have a worksheet with two columns.
First column contains some individual names,
and second column contains Residence PIN number of the individuals.
I want to write a macro that can extract all the individuals for a particular PIN number and store it in another worksheet or workbook.

Could you please help ?
Related:

2 responses

vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 262
Dec 29, 2015 at 07:02 AM
Hello Mishrarameswar,

You could just use the Excel inbuilt filter function and then copy and paste to the next work sheet.
However, if you would still prefer to use a macro, then the following code should do the task for you:-

Sub FindRes()

Application.ScreenUpdating = False

Dim Search As String

Search = InputBox("Please enter the PIN to search.")
If Search = vbNullString Then Exit Sub

With Sheet1
    .AutoFilterMode = False
With Range("B1", Range("B" & Rows.Count).End(xlUp))
        .AutoFilter 1, Search
        .Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(xlUp).Offset(1)
    End With
    .AutoFilterMode = False
End With

Sheet2.Select
Application.ScreenUpdating = True
Application.CutCopyMode = False

End Sub


Basically, the code filters Sheet1 Column B for the PIN that you select and then copies/pastes the relevant information to Sheet2.

Following is a link to my test work book:-

https://www.dropbox.com/s/o5eq8htxhy60tw6/Mishrarameswar.xlsm?dl=0

Click on the "Search PIN" button, an Input Box will appear, enter the required PIN, click OK and the details for that PIN will be transferred over to sheet2.

I hope that this helps.

Cheerio,
vcoolio.
0
mishrarameswar Posts 2 Registration date Tuesday December 29, 2015 Status Member Last seen December 29, 2015
Dec 29, 2015 at 08:58 AM
Thank you much for the reply...

Actually I have to make a report for different routes for the employees.
I have an worksheet which contains Employee Names, Emp. IDs and the PIN number.
Suppose, I have PIN numbers like : 123, 124, 125, 134, 135, 136, 145, 146 etc...

I have to make one report for the employees of PIN 123,124 & 125 and
second report for PINs 134, 135, 136
and third report with PIN 145, & 146

So I want to write the macro for creating those reports in another worksheet or workbook.
0
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 262
Dec 29, 2015 at 06:55 PM
Hello Mishrarameswar,

You really need to tell the whole story in your very first post.

Hence, it would be best if you could upload a sample of your work book (be careful with any sensitive data) so that we can see exactly what it is that you are wanting to do.

To upload a sample, you can use any free file sharing site such as DropBox, ge.tt or SpeedyShare and then post back here with the link to your sample work book.

Cheerio,
vcoolio.
0