Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Kay Kay is offline
external usenet poster
 
Posts: 129
Default macro to find data and filter it and copy to another worksheet

I have a worksheet which has many columns,
what i would like to do that under "Description" column i have such statements
"Suggest resource for "SAP Services Engineer" position on project"
Suggest resource for "Oracle Services Engineer" position on project
So i want to create a macro which will look for "SAP" word in "Description"
column and then filter those rows and copy those rows to other sheet.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default macro to find data and filter it and copy to another worksheet

Hi,
Say your data is in sheet sheet1 and Description is in column B.
And you want to copy the result in Sheet2 at the end of the cells already
used (by checking first column).
Note: if you want cells exactly equal to "SAP", search for "SAP", otherwise,
for
cells containing SAP, search for "*SAP*" (using the wildcard *)
Copy the code below in a module and run the sub Test.

Sub test()
FindCopyRows "*SAP*",sheet1.Range("B:b"),sheet2.Columns(1)
FindCopyRows "*oracle*",sheet1.Range("B:b"),sheet2.Columns( 1)
ENd sub

''' ###########################################

''' find values FindWhat in a Where range and copy (not cut) their rows in
''' in column of ToRange
Sub FindCopyRows(FindWhat As Variant, Where As Range, ToRange As Range)
Dim rgResult As Range
Dim copyTo As Range

Set rgResult = FindAll(FindWhat, Where)
If Not rgResult Is Nothing Then
''' find first blank row in destination
Set copyTo = ToRange.Cells(1).EntireColumn
Set copyTo = copyTo.Cells(copyTo.Cells.Count)
Set copyTo = copyTo.End(xlUp).Offset(1, 0)
''' copy rows there
rgResult.EntireRow.Copy copyTo.EntireRow
End If
End Sub


''' ################################################
''' ######## Reusable/supporting code
''' ################################################

''' Find all cells matching a criteria in a range
Public Function FindAll(FindWhat As Variant, Where As Range)
Dim rgResult As Range
Dim firstAddress As String
Dim cell As Range

With Where
''' find first result cell
Set cell = .Find(what:=FindWhat, LookIn:=xlValues, Lookat:=xlWhole,
MatchCase:=False)
''' find other result cells
If Not cell Is Nothing Then
firstAddress = cell.Address
Do
''' add found cell to result range
If rgResult Is Nothing Then
Set rgResult = cell
Else
Set rgResult = Application.Union(rgResult, cell)
End If
''' find next cell
Set cell = .FindNext(cell)
Loop While Not cell Is Nothing And cell.Address < firstAddress
End If
End With
Set FindAll = rgResult
End Function
'##############################################
--
Regards,
Sébastien
<http://www.ondemandanalysis.com
<http://www.ready-reports.com


"kay" wrote:

I have a worksheet which has many columns,
what i would like to do that under "Description" column i have such statements
"Suggest resource for "SAP Services Engineer" position on project"
Suggest resource for "Oracle Services Engineer" position on project
So i want to create a macro which will look for "SAP" word in "Description"
column and then filter those rows and copy those rows to other sheet.

Thanks!

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
Find matching date in another worksheet, copy and paste data Shoney Excel Discussion (Misc queries) 1 November 8th 07 11:45 PM
Macro to filter 3 columns and then copy data then do the same again........ Stuart[_3_] Excel Programming 1 March 1st 07 10:31 PM
A formula to filter data and copy it from one worksheet to another GeneR Excel Worksheet Functions 6 October 25th 06 03:32 AM
How can i copy and paste data when there is a filter in the worksheet.... dalipsinghbisht Excel Discussion (Misc queries) 5 March 18th 06 12:38 PM
find duplicate data and copy to a third worksheet Arnfinn Hakkebo Excel Programming 3 September 15th 04 06:44 PM


All times are GMT +1. The time now is 10:31 PM.

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

About Us

"It's about Microsoft Excel"