ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy rows that matches cell value (https://www.excelbanter.com/excel-programming/424887-copy-rows-matches-cell-value.html)

Kashyap

Copy rows that matches cell value
 
Hi,

I need to copy rows where value of Col L matches with cell A1 and paste in a
different sheet.


Mike H

Copy rows that matches cell value
 
Hi,

Right click the sheet tab with your source data and view code and paste the
code below in. It copies to sheet2 so change to suit

Sub delete_Me()
Dim copyrange As Range
lastrow = Cells(Cells.Rows.Count, "L").End(xlUp).Row
Set MyRange = Range("L2:L" & lastrow)
For Each c In MyRange
If c = Range("A1").Value 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("Sheet2").Range("A1")
End If
End Sub

Nike

"Kashyap" wrote:

Hi,

I need to copy rows where value of Col L matches with cell A1 and paste in a
different sheet.


Kashyap

Copy rows that matches cell value
 
Thanks Nike..



Would you please help with another post of mine...?

Macro to take cell ref of the object


http://www.microsoft.com/communities...9-9a8428960f8e




"Mike H" wrote:

Hi,

Right click the sheet tab with your source data and view code and paste the
code below in. It copies to sheet2 so change to suit

Sub delete_Me()
Dim copyrange As Range
lastrow = Cells(Cells.Rows.Count, "L").End(xlUp).Row
Set MyRange = Range("L2:L" & lastrow)
For Each c In MyRange
If c = Range("A1").Value 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("Sheet2").Range("A1")
End If
End Sub

Nike

"Kashyap" wrote:

Hi,

I need to copy rows where value of Col L matches with cell A1 and paste in a
different sheet.



All times are GMT +1. The time now is 03:44 PM.

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