Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default extract names based on conditions

In Excel I have a long list of names. I want to write a macro to extract all
those names that are a certain age into a new list

eg if my spreadsheet shows

A B
1 Name Age
2 Adam 40
3 Eve 28
4 Frank 40
5 John 43

I want to create the list of people aged 40 ie Adam, Frank in 2 new cells

Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default extract names based on conditions

Hi,

Right click your sheet tab, view code and paste this in and run it.

Sub stantial()
Dim myrange As Range, copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set myrange = Range("A2:A" & Lastrow)
Set copyrange = Range("A1")
For Each c In myrange
If c.Offset(, 1).Value = 40 Then
Set copyrange = Union(copyrange, c)
End If
Next
copyrange.Copy
Range("C1").PasteSpecial
End Sub


Mike

"Bobak" wrote:

In Excel I have a long list of names. I want to write a macro to extract all
those names that are a certain age into a new list

eg if my spreadsheet shows

A B
1 Name Age
2 Adam 40
3 Eve 28
4 Frank 40
5 John 43

I want to create the list of people aged 40 ie Adam, Frank in 2 new cells

Any ideas?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default extract names based on conditions

I would just use DataAutofilter on the age column and copy the visible
cells to a new spot.


Gord Dibben MS Excel MVP

On Wed, 3 Sep 2008 07:38:01 -0700, Bobak
wrote:

In Excel I have a long list of names. I want to write a macro to extract all
those names that are a certain age into a new list

eg if my spreadsheet shows

A B
1 Name Age
2 Adam 40
3 Eve 28
4 Frank 40
5 John 43

I want to create the list of people aged 40 ie Adam, Frank in 2 new cells

Any ideas?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract domain names from email IDs sl24 Excel Worksheet Functions 2 August 21st 07 05:05 PM
shade cells based on conditions - i have more than 3 conditions Mo2 Excel Worksheet Functions 3 March 30th 07 07:19 AM
Counting based upon 2 conditions that are text based walkerdayle Excel Discussion (Misc queries) 7 August 22nd 06 01:29 AM
Formula to Extract value on 3 column based on two conditions wayliff Excel Discussion (Misc queries) 0 January 12th 06 08:20 PM
How do I extract the last name in Excel, from a list of names lik. RobertC Excel Worksheet Functions 4 November 17th 04 06:52 AM


All times are GMT +1. The time now is 02:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"