ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel (https://www.excelbanter.com/excel-discussion-misc-queries/253156-excel.html)

Bhameo

Excel
 
How can I search a column for specific values and have all rows that contain
these values copied to another sheet?

Mike H

Excel
 
Hi,

Not too much infor but here's a macro that will do it. It looks in Column A.
Change the string to search for and the source and destination sheets to suit

Sub stance()
Dim MyRange As Range
Dim CopyRange As Range
Dim MyString As String
Dim SrcSht As String
Dim DestSht As String
Dim LastRow As Long
MyString = "XXX" ' change to suit must be in uppercase
SrcSht = "Sheet1" ' change to suit
DestSht = "Sheet2" ' change to suit
LastRow = Sheets(SrcSht).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets(SrcSht).Range("A1:A" & LastRow)
For Each c In MyRange

If UCase(c.Value) = MyString Then
If CopyRange Is Nothing Then
Set CopyRange = c.EntireRow
Else
Set CopyRange = Union(CopyRange, c.EntireRow)
End If
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Destination:=Sheets(DestSht).Range("A1")
End If
End Sub


Mike

"Bhameo" wrote:

How can I search a column for specific values and have all rows that contain
these values copied to another sheet?


Gord Dibben

Excel
 
DataFilterAutofilter.

F5SpecialVisible cells only.

Copypaste to other sheet.


Gord Dibben MS Excel MVP

On Tue, 12 Jan 2010 12:33:01 -0800, Bhameo
wrote:

How can I search a column for specific values and have all rows that contain
these values copied to another sheet?




All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com