Pull Specific Data from one Sheet to Another using Macro

MarkHutch

New Member
Joined
Dec 14, 2017
Messages
8
Hi

I was wondering if anyone was able to help. I have a set of data in one Sheet and I need specific Data from that sheet moved to a second sheet and a comment added. So For example Sheet 1 has Columns A through E with all employees data. I would need this data moved to sheet 2, which has those columns plus extras through to column K. But I would need only specific employee’s info. This I’m hoping could be done by say ID and for instance take only 50012345 John Smith and 50098765 Adam Apples (along with the rest of the relevant info for dates, start time and finish time. Column F is then normally blank. For those same specific employees, I would need this to be populated with the word ‘Travel’. Then again in the comments section, a comment would need to be added, which is again specific to the employee (ID number). Is this possible to do with a macro? Right now we are having to manually do this and it takes ages.
Some data may also already exist in Sheet 2, Would it be possible for any new data being brought into this to be applied under the data already in there. Or would it need to be a completely different sheet and then a copy and paste done?

Any assistance you can provide would be greatly appreciated. This is doing my head in :)
Thanks

Safe journeys

Mark
A
B
C
D
E
F
G
H
I
J
K
Name
ID
NA Date
StartTime
FinishTime
NonAvailability
CommentText
Street
City
PostCode
CountryID
John Smith
50012345
15/07/2016
00:00
08:59
Travel
Gone Shopping
John Smith
50012345
16/07/2016
00:00
23:59
Travel
Gone Shopping
John Smith
50012345
17/07/2016
00:00
23:59
Travel
Gone Shopping
John Smith
50012345
18/07/2016
00:00
08:59
Travel
Gone Shopping
Bob Brown
50076543
01/08/2016
17:00
23:59
Travel
Visiting Parents
Bob Brown
50076543
02/08/2016
00:00
08:59
Travel
Visiting Parents
Bob Brown
50076543
02/08/2016
17:00
23:59
Travel
Visiting Parents
Bob Brown
50076543
03/08/2016
00:00
08:59
Travel
Visiting Parents
Adam Apples
50098765
27/07/2016
17:00
23:59
Travel
Gone Fishing
Adam Apples
50098765
28/07/2016
00:00
08:59
Travel
Gone Fishing
Adam Apples
50098765
28/07/2016
17:00
23:59
Travel
Gone Fishing
Adam Apples
50098765
29/07/2016
00:00
08:59
Travel
Gone Fishing
Adam Apples
50098765
29/07/2016
17:00
23:59
Travel
Gone Fishing

<tbody>
</tbody>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Are the IDs you want to copy over always the same?
If not, how is it determined?
Is the comment always the same for a specific employee, or can that change?
 
Upvote 0
Hi, the ID for the employee remains the same, its their employee ID Number, as does the comment for that employee. Basically I have a list of 30 employees with their own unique ID number. The macro would need to pull their details from the one sheet and put it on the other. Then add the word Travel to column F for each of those. Then add the respective comment in column G which is unique to each employee and their ID. Does that make sense?
 
Upvote 0
In your example, you said
50012345 John Smith and 50098765 Adam Apples
Would it always be those 2 IDs, or will the IDs to copy change every time you run the macro?
 
Upvote 0
There are 30 ID's. So it would need to search the data in Sheet1 and pull all data in first columns (A-E) for any matches to those ID's. The ID's will stay the same unless people left or we had new starter.
Then it would add the word Travel to the next column and the comments specific to that ID in the next column.
 
Upvote 0
Where are these 30 IDs stored? and where are the comments stored?
 
Upvote 0
you could use like 001 to 0030 for example ID's. I'm sure its then possible to edit it with the correct ID numbers. Column F would always be 'Travel'. Then Column G could be 'Comment1' to 'Comment30'. Again as long as it would be possible to then edit it with the correct comment.
Really appreciate your help with this :biggrin:
 
Upvote 0
How about
Code:
Sub CopyFromList()

   Dim NxtRw As Long
   Dim Usdrws As Long
   Dim Ary As Variant
   Dim Cnt As Long
   
   NxtRw = Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Range("A" & Rows.Count).End(xlUp).Offset(1).row
   With Sheets("[COLOR=#ff0000]ID[/COLOR]")
      Ary = Application.Transpose(.Range("A2", .Range("A" & Rows.Count).End(xlUp)))
   End With
   
   For Cnt = LBound(Ary) To UBound(Ary)
      Ary(Cnt) = CStr(Ary(Cnt))
   Next Cnt
      
   With Sheets("Source")
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1:E1").AutoFilter 2, Ary, xlFilterValues
      .Range("A2:E" & .Range("B" & Rows.Count).End(xlUp).row).SpecialCells(xlVisible).Copy Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Range("A" & NxtRw)
      .AutoFilterMode = False
   End With
   
   With Sheets("[COLOR=#ff0000]Sheet2[/COLOR]")
      Usdrws = .Range("A" & Rows.Count).End(xlUp).row
      .Range("F" & NxtRw & ":F" & Usdrws).Value = "Travel"
      With .Range("G" & NxtRw & ":G" & Usdrws)
         .FormulaR1C1 = "=VLOOKUP(rc[-5],[COLOR=#ff0000]ID[/COLOR]!r2c1:r30c2,2,FALSE)"
         .Value = .Value
      End With
   End With

End Sub
Change Sheet names in red to suit.
You'll need a sheet set up like this, for your IDs & comments.


Excel 2013 32 bit
AB
1IDComment
229221Peartree
342644Ladywood
438534Sparkbrook
529231Edgbaston
632051Cofton
735765Lickey Hills
831503Slideslow
936678Avoncroft
1035947Charford
1134700Langley
1237438Kingsbury
1330011Fazeley
1437469Sheldon
1537653Elmdon
1642217Kingsmead
1738838Weston
1834182Lambridge
1941821Newbridge
2038504Frome
2137622Mere
2242401Warminster
2338412Trowbridge
2431594Melksham
2540422Hilperton
2637895Ethandune
2735400Southwick
2838353Timsbury
2934881Oldfield
3038718Westmoreland
ID


As for the email, Who did it say had responded?
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top