Filter Column and copy the other values in same row but other columns to new worksheet

miss_anonymous

New Member
Joined
May 25, 2011
Messages
4
Good evening guys,

Unfortunatelly my (huge) reference book for excel is not able to answer my current makro question:

In my worksheet "data" is my data collection.
There I want to filter Column B (containing all eyecolors) for only "green" and copy the other values within the same row in Column D (age) and Column F (gender) to a new worksheet.

new worksheet side by side:
eyecolor_____age__________gender__
green 7 female
green 8 male
green 9 female

I'm not sure how to create the indirect cell reference for EXCEL 2003.

Sorry for bothering you, but my little makro skills reach theirs here.

It would be great hearing of you!

Miss_Anonymous
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Something similar to this might work but there's lots of better ways.

Code:
Public Sub Test1()
 
Set theRange = Intersect(ThisWorkbook.Sheets("Data").Range("B:B"), ThisWorkbook.Sheets("Data").UsedRange)
 
If theRange Is Nothing Then: MsgBox "No data in column B": Exit Sub: End If
 
For Each Cell in theRange
 
    If Cell = "Green" Then 
        a = a + 1
        If a = 1 then set b = ThisWorkbook.Sheets.Add After:=ThisWorkbook.Sheets("Data")
 
        With b
 
            .Name = "Filtered Data from " & TimeValue(Now)
            .Range("a1") = "Eyecolor" 
            .Range("a2") = "Age"
            .Range("a3") = "Gender"
 
 
        End If
 
            .Range("a1").Offset(a,0) = Cell
            .Range("b1").Offset(a,0) = Cell.Offset(,2)
            .Range("c1").Offset(a,0) = Cell.Offset(,3)
 
        End With
 
Next
 
End Sub
 
Upvote 0
Thank you very much for your great input.

I'm afraid, but the error message is "synthax error"

concerning this line:

If a = 1 then set b = ThisWorkbook.Sheets.Add After:=ThisWorkbook.Sheets("Data")

Can anyone help me?

the Code so far:

Public Sub Test2()

Dim a As Integer

Set theRange = Intersect(ThisWorkbook.Sheets("Data").Range("C4:C13"), ThisWorkbook.Sheets("Data").UsedRange)


For Each Cell In theRange

If Cell = "brown" Then
a = a + 1
If a = 1 then set b = ThisWorkbook.Sheets.Add After:=ThisWorkbook.Sheets("Data")

With b

.Name = "Filtered Data from " & TimeValue(Now)
.Range("a1") = "Eyecolor"
.Range("a2") = "Age"
.Range("a3") = "Gender"




.Range("a1").Offset(a, 0) = Cell
.Range("b1").Offset(a, 0) = Cell.Offset(, 2)
.Range("c1").Offset(a, 0) = Cell.Offset(, 3)

End With
End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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