ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy range if match (https://www.excelbanter.com/excel-programming/425328-copy-range-if-match.html)

J.W. Aldridge

Copy range if match
 
Sheet 1. Has two sets of data. B6:G and I6:N.

The code below copies the numbers in column B if they have a match in
column I.

How should I go about changing to copy not only B, but the remaining
row info (B through G) if match. ?


Sub ABC()
Dim cell As Range, c As Range
Dim i As Range, rw As Long
Dim sh As Worksheet
With Worksheets("Data")
Set c = .Range(.Cells(6, "B"), .Cells(6, "B").End(xlDown))
Set i = .Range(.Cells(6, "I"), .Cells(6, "I").End(xlDown))
End With
rw = 2


Set sh = Worksheets("RESULTS")
For Each cell In c
If Application.CountIf(i, cell) 0 Then
sh.Cells(rw, 1) = cell
rw = rw + 1
End If
Next
End Sub



[email protected]

Copy range if match
 
On Mar 10, 10:20*am, "J.W. Aldridge"
wrote:
Sheet 1. Has two sets of data. B6:G and I6:N.

The code below copies the numbers in column B if they have a match in
column I.

How should I go about changing to copy not only B, but the remaining
row info (B through G) if match. ?

Sub ABC()
Dim cell As Range, c As Range
Dim i As Range, rw As Long
Dim sh As Worksheet
With Worksheets("Data")
Set c = .Range(.Cells(6, "B"), .Cells(6, "B").End(xlDown))
Set i = .Range(.Cells(6, "I"), .Cells(6, "I").End(xlDown))
End With
rw = 2

Set sh = Worksheets("RESULTS")
For Each cell In c
If Application.CountIf(i, cell) 0 Then
* sh.Cells(rw, 1) = cell
* rw = rw + 1
End If
Next
End Sub


I'm not quite sure if I follow what you are asking exactly, but the
following code may be of help to you:

Best,

Matt Herbert

If Application.CountIf(i, cell) 0 Then
Range(cell, Cells(cell.Row, "G")).Copy sh.Cells(rw, 1)
rw = rw + 1
End If

J.W. Aldridge

Copy range if match
 
Thanx.!
That worked purfectly!

When I make my first million... I'm buying you a Krystal! (or White
Castle)
And that's WITH cheese my friend!


All times are GMT +1. The time now is 07:37 AM.

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