+ Reply to Thread
Results 1 to 4 of 4

Macro that searches column B in all sheets for all the different values and return in list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-09-2013
    Location
    California, USA
    MS-Off Ver
    MS 365 Subscription
    Posts
    130

    Macro that searches column B in all sheets for all the different values and return in list

    I have a macro that looks for all the different values in column B and returns the different values only once in a list. I am trying to get this macro to do the same thing but to look in all the sheets column B and return all the different values onto on sheet. Here is the code I'm using to do it with one sheet.

    Range(Range("B4"), Range("B4").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, _
        CopyToRange:=Range("I4"), Unique:=True

    Thank you
    Last edited by pasqualebaldi; 12-29-2014 at 12:58 PM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,875

    Re: Macro that searches column B in all sheets for all the different values and return in

    You can loop through all sheets, collecting the data the same way (unfortunately, as far as I remember advanced filter output has to go to the same sheet as data) and copying into "final sheet" then you can do the same in the final sheet.

    Other option (if total number of used rows in do not exceed excel limits) you can copy all data into "final sheet" and then deduplicate it there.

    anyway you will need a loop through all sheets skipping the one where output shall be placed, so something like:

    dim ws as worksheet
    for each ws in worksheets
      if ws.name <> "FinalResultsSheetName" then
       ' do all needed actions
      end if
    next ws
    Best Regards,

    Kaper

  3. #3
    Forum Contributor
    Join Date
    09-09-2013
    Location
    California, USA
    MS-Off Ver
    MS 365 Subscription
    Posts
    130

    Re: Macro that searches column B in all sheets for all the different values and return in

    I am taking your advice and I'm trying to copy each dynamic list in column "B" from all the sheets and then paste them in one long list on the last sheet "Total Quantities" so I can run the advanced filter macro. I know I am doing something wrong though:
    Sub find_all()
    
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
    Dim ws As Worksheet
    For Each ws In Worksheets
      If ws.Name <> "Total Quantities" Then
      
       copylist = Cells(Rows.Count, "B").End(xlUp).Row
       Range("B4:B" & copylist).Copy Destination:=Sheets("Total Quantities").Range("A1:A" & LastRow)
       
      End If
    Next ws
    
    End Sub

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,875

    Re: Macro that searches column B in all sheets for all the different values and return in

    Try rearanging commands (last row changes after something is copied into the sheet)

    Sub find_all_unique()
    
    Dim ws As Worksheet, copylist as long, lastrow as long
    For Each ws In Worksheets
      If ws.Name <> "Total Quantities" Then
      
       copylist = ws.Cells(Rows.Count, "B").End(xlUp).Row 'note ws. - you want to look in ws sheet
       LastRow = Sheets("Total Quantities").Cells(Rows.Count, "A").End(xlUp).Row 
    
       ws.Range("B4:B" & copylist).Copy Destination:=Sheets("Total Quantities").Range("A" & LastRow+1) 'note +1 (and again ws.)
       
      End If
    Next ws
    'and now dedupe
    LastRow = Sheets("Total Quantities").Cells(Rows.Count, "A").End(xlUp).Row 
    Sheets("Total Quantities").Range("A1:A"&lastrow).RemoveDuplicates Columns:=1, Header:=xlNo
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 14
    Last Post: 07-29-2013, 05:41 PM
  2. Replies: 1
    Last Post: 06-14-2013, 09:01 PM
  3. [SOLVED] Formula to match data in different sheets ( multi column) and return matching values
    By kangyao in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-11-2013, 07:38 PM
  4. Replies: 1
    Last Post: 10-28-2011, 03:13 AM
  5. Returning values from column A, using searches from Column B
    By English_Bloke82 in forum Excel General
    Replies: 3
    Last Post: 03-30-2011, 02:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1