ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy lines with specific value (https://www.excelbanter.com/excel-programming/393113-copy-lines-specific-value.html)

Robert[_30_]

Copy lines with specific value
 
Hi,

I would like to extend the below statement with a second lookup, i.e.
besides copying all lines with value RNWD I wouls also like to copy
the ones with RNTJ
Could someone tell me how to incorporate this additional command?

Many thanks!

Rgds,
Robert


Dim iLastRow As Long, iNextRow As Long
Dim i As Long
With Worksheets("Positions")
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, "A").Value = "RNWD" Then
iNextRow = iNextRow + 1
.Cells(i, "A").Resize(, 21).Copy _
Worksheets("Futures").Cells(iNextRow, "A")
End If
Next i

End With


Dan R.

Copy lines with specific value
 
Robert,

Just replace this:
If .Cells(i, "A").Value = "RNWD" Then

With this:
If .Cells(i, "A").Value = "RNWD" Or .Cells(i, "A").Value = "RNTJ" Then

--
Dan


johnboy

Copy lines with specific value
 
Robert,
is this what you want?

Dim iLastRow As Long, iNextRow As Long
Dim i As Long
With Worksheets("Positions")
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, "A").Value = "RNWD" Or _
.Cells(i, "A").Value = "RNTJ" Then
iNextRow = iNextRow + 1
.Cells(i, "A").Resize(i, 21).Copy _
Worksheets("Futures").Cells(iNextRow, "A")
End If
Next i
End With
--
JB


"Robert" wrote:

Hi,

I would like to extend the below statement with a second lookup, i.e.
besides copying all lines with value RNWD I wouls also like to copy
the ones with RNTJ
Could someone tell me how to incorporate this additional command?

Many thanks!

Rgds,
Robert


Dim iLastRow As Long, iNextRow As Long
Dim i As Long
With Worksheets("Positions")
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, "A").Value = "RNWD" Then
iNextRow = iNextRow + 1
.Cells(i, "A").Resize(, 21).Copy _
Worksheets("Futures").Cells(iNextRow, "A")
End If
Next i

End With



Robert[_30_]

Copy lines with specific value
 
Thanks a lot Dan!!



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

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