ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy & Paste...if (https://www.excelbanter.com/excel-programming/405722-copy-paste-if.html)

Saintsman

Copy & Paste...if
 
I want to copy values from ColB (Range2) but paste only if values in ColA
(Range1) = a specified value eg yes. I work with named ranges
ColA ColB result (different sheet)
yes 10 10
yes 12 12
no 5 30
no 10
yes 30
no 12
Any help as always gratefully received

joel

Copy & Paste...if
 

Sub test()

RowCount = 1
NewRowCount = 1
With ActiveSheet
Do While .Range("A" & RowCount) < ""
If .Range("A" & RowCount) = "Yes" Then
.Range("B" & RowCount).Copy _
Destination:=Sheets("NewSheet").Range("A" & NewRowCount)
NewRowCount = NewRowCount + 1
End If

RowCount = RowCount + 1
Loop
End With

End Sub

"Saintsman" wrote:

I want to copy values from ColB (Range2) but paste only if values in ColA
(Range1) = a specified value eg yes. I work with named ranges
ColA ColB result (different sheet)
yes 10 10
yes 12 12
no 5 30
no 10
yes 30
no 12
Any help as always gratefully received



All times are GMT +1. The time now is 02:14 PM.

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