Trying to extract data from one sheet and list it in another...<p>Hi, i have a sheet with lots of employee data on it including the manager name.  I want to loop through each employee and make a list of the managers and display this in sheet 2.  I only want each manager to be displayed once no matter how many times he occurs.<br><br>Here is what i have so far - probably very messy but its the best i can come up with! <br><br> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p>Option Explicit</p> <p>Sub manager_list()</p> <p>'declare all variables and initilize<br>Dim s1, s2 As Worksheet</p> <p>Dim x As Integer<br>Dim Manager As String</p> <p>Dim rngManager As Range<br>Dim c As Range</p> <p>Set s1 = ThisWorkbook.Worksheets(&quot;Sheet1&quot;)<br>Set s2 = ThisWorkbook.Worksheets(&quot;Sheet2&quot;)</p> <p>'range set to first column in sheet 2 - Manager names<br>Set rngManager = s2.Range(s2.Range(&quot;A2&quot;), s2.Range(&quot;A2&quot;).End(xlDown))</p> <p>Manager = &quot;E&quot; &amp; x</p> <p>'loop through all employees on sheet 1<br>For x = 2 To 1000</p> <p>    'Loop through all managers on sheet 2<br>    For Each c In rngManager.Cells<br>        <br>        'see if manager has already been copied to sheet 2 column A<br>        <font style="background-color:#ffff00">If Range(Manager).Value = c.Value Then</font><br>           GoTo NEXT_REC<br>        Else<br>            'copy manager from sheet 1<br>            Range(Manager).Value.Select<br>            Selection.Copy<br>            'paste into sheet 2<br>            c.Select<br>            Selection.Paste<br>        End If<br>    <br>    Next<br>NEXT_REC:<br>Next</p> <p>End Sub</p></div></div> <p> </p> <p>Its bringing up an error on the highlighted line above.  <br><br>Any help is great thanks <img height=19 alt=Smile src="http://forums.microsoft.com/MSDN/emoticons/emotion-1.gif" width=19> </p> <p> </p> <p><br> </p>© 2009 Microsoft Corporation. All rights reserved.Wed, 10 Dec 2008 23:25:30 Z7a3425c8-1238-4f51-a5a1-a76a4aaabdadhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/7a3425c8-1238-4f51-a5a1-a76a4aaabdad#7a3425c8-1238-4f51-a5a1-a76a4aaabdadhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/7a3425c8-1238-4f51-a5a1-a76a4aaabdad#7a3425c8-1238-4f51-a5a1-a76a4aaabdadScott Boydhttp://social.msdn.microsoft.com/Profile/en-US/?user=Scott%20BoydTrying to extract data from one sheet and list it in another...<p>Hi, i have a sheet with lots of employee data on it including the manager name.  I want to loop through each employee and make a list of the managers and display this in sheet 2.  I only want each manager to be displayed once no matter how many times he occurs.<br><br>Here is what i have so far - probably very messy but its the best i can come up with! <br><br> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p>Option Explicit</p> <p>Sub manager_list()</p> <p>'declare all variables and initilize<br>Dim s1, s2 As Worksheet</p> <p>Dim x As Integer<br>Dim Manager As String</p> <p>Dim rngManager As Range<br>Dim c As Range</p> <p>Set s1 = ThisWorkbook.Worksheets(&quot;Sheet1&quot;)<br>Set s2 = ThisWorkbook.Worksheets(&quot;Sheet2&quot;)</p> <p>'range set to first column in sheet 2 - Manager names<br>Set rngManager = s2.Range(s2.Range(&quot;A2&quot;), s2.Range(&quot;A2&quot;).End(xlDown))</p> <p>Manager = &quot;E&quot; &amp; x</p> <p>'loop through all employees on sheet 1<br>For x = 2 To 1000</p> <p>    'Loop through all managers on sheet 2<br>    For Each c In rngManager.Cells<br>        <br>        'see if manager has already been copied to sheet 2 column A<br>        <font style="background-color:#ffff00">If Range(Manager).Value = c.Value Then</font><br>           GoTo NEXT_REC<br>        Else<br>            'copy manager from sheet 1<br>            Range(Manager).Value.Select<br>            Selection.Copy<br>            'paste into sheet 2<br>            c.Select<br>            Selection.Paste<br>        End If<br>    <br>    Next<br>NEXT_REC:<br>Next</p> <p>End Sub</p></div></div> <p> </p> <p>Its bringing up an error on the highlighted line above.  <br><br>Any help is great thanks <img height=19 alt=Smile src="http://forums.microsoft.com/MSDN/emoticons/emotion-1.gif" width=19> </p> <p> </p> <p><br> </p>Tue, 03 Apr 2007 09:43:44 Z2007-04-03T12:21:12Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/7a3425c8-1238-4f51-a5a1-a76a4aaabdad#d4fc36cd-26c9-405e-a403-88d76a1fd4c6http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/7a3425c8-1238-4f51-a5a1-a76a4aaabdad#d4fc36cd-26c9-405e-a403-88d76a1fd4c6Keithyboy1http://social.msdn.microsoft.com/Profile/en-US/?user=Keithyboy1Trying to extract data from one sheet and list it in another...<p>It would be easiest to use the AdvancedFilter method of the Range class to do this.</p> <p> </p> <p>Define a range variable that represents the column of managers in your employee list (We'll call this Range1). Also define a range variable that represents a cell where you want the unique list to begin (we'll call this Range2). The latter can be on another worksheet if desired. Then the following code should do the trick:</p> <p> </p> <p>Range1.AdvancedFilter xlFilterCopy, CopyToRange:=Range2, Unique:=True</p> <p> </p> <p> </p>Tue, 03 Apr 2007 11:16:45 Z2007-04-03T12:21:12Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/7a3425c8-1238-4f51-a5a1-a76a4aaabdad#bbe6c04f-0717-4dee-b39d-ea480ae0661ahttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/7a3425c8-1238-4f51-a5a1-a76a4aaabdad#bbe6c04f-0717-4dee-b39d-ea480ae0661aScott Boydhttp://social.msdn.microsoft.com/Profile/en-US/?user=Scott%20BoydTrying to extract data from one sheet and list it in another...Many thanks mate - that's a much neater and more efficient solution! <img height=19 alt=Smile src="http://forums.microsoft.com/MSDN/emoticons/emotion-1.gif" width=19>Tue, 03 Apr 2007 12:50:22 Z2007-04-03T12:50:22Z