find match values and copy

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,286
Office Version
  1. 2013
Platform
  1. Windows
Good Day,
I have a datas on the columns ("A1:C1500)
I want to populate those values into columns (H:J)
which matching the cell ("M1") value , with column ("C") values all the way down..
Many Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then .Offset(, -2).Resize(, 3).Copy Destination:=Range("H" & Rows.Count).End(xlUp).Offset(1)
    End With
Next i
End Sub
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then .Offset(, -2).Resize(, 3).Copy Destination:=Range("H" & Rows.Count).End(xlUp).Offset(1)
    End With
Next i
End Sub


Thanks Vog,
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then .Offset(, -2).Resize(, 3).Copy Destination:=Range("H" & Rows.Count).End(xlUp).Offset(1)
    End With
Next i
End Sub

Vog,
is it possible to change to copy function like with filling or inserting coz Target Range properties changing such font size& color or table etc.....
Thanks
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then
            .Offset(, -2).Resize(, 3).Copy
            Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        End If
    End With
Next i
End Sub
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then
            .Offset(, -2).Resize(, 3).Copy
            Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        End If
    End With
Next i
End Sub


Thanks Again Vog,
If i do add more target values like M1,M2,,, together its fine by placing the codes together..
but how can i skip 1 row down after the first code run then the second can give me seperated result for to better view?
 
Last edited:
Upvote 0
Perhaps like this

Rich (BB code):
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then
            .Offset(, -2).Resize(, 3).Copy
            Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        End If
    End With
Next i
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = " "
End Sub
 
Upvote 0
Perhaps like this

Rich (BB code):
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then
            .Offset(, -2).Resize(, 3).Copy
            Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        End If
    End With
Next i
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = " "
End Sub


Code:
Sub Button3_Click()
Application.ScreenUpdating = False
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
With Range("A" & i)
If .Value = Range("AA1").Value Then
.Offset(, 1).Resize(, 4).Copy
Range("AE" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End With
Next i
 
Range("AE" & Rows.Count).End(xlUp).Offset(1).Value = " "
 
Dim LMR As Long, ip As Long
LMR = Range("A" & Rows.Count).End(xlUp).Row
For ip = 1 To LMR
With Range("A" & ip)
If .Value = Range("AA2").Value Then
.Offset(, 1).Resize(, 4).Copy
Range("AE" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End With
Next ip
 
Application.ScreenUpdating = True
End Sub

Many Thanks.
Its OK now!
 
Upvote 0
Perhaps like this

Rich (BB code):
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = Range("M1").Value Then
            .Offset(, -2).Resize(, 3).Copy
            Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        End If
    End With
Next i
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = " "
End Sub


Code:
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
With Range("A" & i)
If .Value = ComboBox1.Value Then
.Offset(, 1).Resize(, 4).Copy
Range("AE" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End With
Next i

Range("AE" & Rows.Count).End(xlUp).Offset(2).Value = " "

Dim LMR As Long, ip As Long
LMR = Range("A" & Rows.Count).End(xlUp).Row
For ip = 1 To LMR
With Range("A" & ip)
If .Value = ComboBox2.Value Then
.Offset(, 1).Resize(, 4).Copy
Range("AE" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End With
Next ip

Vog i need ur help on my last task,
if no value in combobox2 how can i prevent that second code runing?
Thanks
 
Upvote 0
Perhaps like this

Rich (BB code):
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
With Range("A" & i)
If .Value = ComboBox1.Value Then
.Offset(, 1).Resize(, 4).Copy
Range("AE" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End With
Next i

Range("AE" & Rows.Count).End(xlUp).Offset(2).Value = " "
If ComboBox2.Value = "" Then Exit Sub
Dim LMR As Long, ip As Long
LMR = Range("A" & Rows.Count).End(xlUp).Row
For ip = 1 To LMR
With Range("A" & ip)
If .Value = ComboBox2.Value Then
.Offset(, 1).Resize(, 4).Copy
Range("AE" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End With
Next ip
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top