ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy entire row if... (https://www.excelbanter.com/excel-programming/317785-copy-entire-row-if.html)

Sam

Copy entire row if...
 
I need help copying entire row from "table1.xls" if column B is "text1" to
"table2.xls". what is the most simple way of doing this?

Thanks
--
-Sam

Bob Phillips[_6_]

Copy entire row if...
 

If Cells(2,"B") = "text1" Then
Cells(2,"B").Entirerow.Copy
Destination:=Workbooks("table2.xls").Worksheets("S heet1").Range("A1")
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Sam" wrote in message
...
I need help copying entire row from "table1.xls" if column B is "text1" to
"table2.xls". what is the most simple way of doing this?

Thanks
--
-Sam




Sam

Copy entire row if...
 
Thanks Bob, that was very helpful. There is still one more detail I want to
solve. I want to be able to put more than one row in destination table, so
that the data is saved always to next empty row. Because of this I can't
order the certain range.

Bob Phillips[_6_]

Copy entire row if...
 
Sam,

Try something like


If Cells(2,"B") = "text1" Then
Set oWS = Workbooks("table2.xls").Worksheets("Sheet1")
cLastRow = oWS.Cells(Rows.Count,"A").End(xlUp).Row
Cells(2,"B").Entirerow.Copy
Destination:=.oWS.Cells(cLastRow+1,"A")
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Sam" wrote in message
...
Thanks Bob, that was very helpful. There is still one more detail I want

to
solve. I want to be able to put more than one row in destination table, so
that the data is saved always to next empty row. Because of this I can't
order the certain range.




Don Guillett[_4_]

Copy entire row if...
 
then change to this idea

With workbooks"table2.xls").worksheets("sheet1")
If Cells(2,"B") = "text1" Then
x = .Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(2, "b").EntireRow.Copy .Cells(x, 1)
End With
end if
End Sub

If Cells(2,"B") = "text1" Then
Cells(2,"B").Entirerow.Copy
Destination:=Workbooks("table2.xls").Worksheets("S heet1").Range("A1")
End If


--
Don Guillett
SalesAid Software

"Sam" wrote in message
...
Thanks Bob, that was very helpful. There is still one more detail I want

to
solve. I want to be able to put more than one row in destination table, so
that the data is saved always to next empty row. Because of this I can't
order the certain range.




Don Guillett[_4_]

Copy entire row if...
 
change position of end with and end if

--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
then change to this idea

With workbooks"table2.xls").worksheets("sheet1")
If Cells(2,"B") = "text1" Then
x = .Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(2, "b").EntireRow.Copy .Cells(x, 1)
End With
end if
End Sub

If Cells(2,"B") = "text1" Then
Cells(2,"B").Entirerow.Copy
Destination:=Workbooks("table2.xls").Worksheets("S heet1").Range("A1")
End If


--
Don Guillett
SalesAid Software

"Sam" wrote in message
...
Thanks Bob, that was very helpful. There is still one more detail I want

to
solve. I want to be able to put more than one row in destination table,

so
that the data is saved always to next empty row. Because of this I can't
order the certain range.






Sam

Copy entire row if...
 
Thanks guys! Now it works

Don Guillett[_4_]

Copy entire row if...
 
glad to help

--
Don Guillett
SalesAid Software

"Sam" wrote in message
...
Thanks guys! Now it works





All times are GMT +1. The time now is 12:08 AM.

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