ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel macro (https://www.excelbanter.com/excel-programming/386017-excel-macro.html)

Pierre Fichaud

Excel macro
 
I would like to extract rows from one sheet and add them to another
sheet if there is the character 's' is in the cell under column k. How
do I do this? TIA.

--
Posted via a free Usenet account from http://www.teranews.com


Tom Ogilvy

Excel macro
 
Sub CopyData()
Dim cell as range, rng1 as Range, rng as range
Dim sh as worksheet
With worksheets("Sheet1")
set rng = .Range(.cells(2,"k"),.cells(2,"k").End(xlup))
End with
set sh = worksheets("Sheet2")
for each cell in rng
if lcase(cell.value) = "s" then
if rng1 is nothing then
set rng1 = cell
else
set rng1 = union(rng1,cell)
end if
end if
Next
if not rng1 is nothing then
rng1.EntireRow.Copy Destination:= _
sh.cells(rows.count,1).end(xlup)(2)
End if
End sub

--
Regards,
Tom Ogilvy


"Pierre Fichaud" wrote in message
.. .
I would like to extract rows from one sheet and add them to another sheet
if there is the character 's' is in the cell under column k. How do I do
this? TIA.

--
Posted via a free Usenet account from http://www.teranews.com





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

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