Question

2 columns on master sheet:

col1      col2
Apple     Fruit
Spinach   Veg
Orange    Fruit
Potatoe   Veg   
Pear      Fruit
Bannana   Fruit
Carrot    Veg
Potataoe  Veg

Say I wanted to copy all Fruit data to a another sheet and all Veg data to a 3rd sheet. Is there a way to do this? Does it require a macro or can I somehow do a VLOOKUP?

Also I need this to be dynamic, so if a new row is added the corresponding sheets are updated.

Was it helpful?

Solution

You could use this horrible monstrosity of a formula:

=INDEX($B$2:$B$9, SMALL(IF("veg"=$A$2:$A$9, ROW($A$2:$A$9)-MIN(ROW($A$2:$A$9))+1, ""), ROW(A1)))

Enter it as an array formula with Ctrl+Shift+Enter.

HorribleMonstrousityFormula

I found the formula here: http://www.get-digital-help.com/2009/10/25/how-to-return-multiple-values-using-vlookup-in-excel/

Which might not be the best version or most elegant version of this formula(it is a common formula task) but it will get the job done.

OTHER TIPS

I'd use PivotTables (using Excel 2007) but you will need to refresh each time the source is modified/extended and to keep an eye on Table/Data Range: not stopping short of any additions:

SO12932741 example

  • right click your sheet tab
  • View Code
  • copy and paste in the code below

whenever column B is changed the code

  1. AutoFilters column B for "Fruit", then copies records to sheet 2 columns A:B
  2. AutoFilters column B for "Veg", then copies records to sheet 2 columns A:B

Code

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng1 As Range
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set rng1 = Intersect([B:B], Target)
If rng1 Is Nothing Then Exit Sub
Set ws1 = Sheets(2)
Set ws2 = Sheets(3)
ws1.[A:B].ClearContents
ws2.[A:B].ClearContents
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A:B")
.AutoFilter Field:=2, Criteria1:="Fruit"
.Copy ws1.[a1]
.AutoFilter Field:=2, Criteria1:="Veg"
.Copy ws2.[a1]
End With
ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top