Automating copy and paste based on cell value PLS HELP

Waffels

New Member
Joined
Oct 15, 2017
Messages
4
[TABLE="width: 963"]
<colgroup><col span="5"><col><col span="3"><col><col span="2"><col><col></colgroup><tbody>[TR]
[TD]1[/TD]
[TD]301[/TD]
[TD]88[/TD]
[TD]4155[/TD]
[TD] [/TD]
[TD]MRPXX123[/TD]
[TD]000[/TD]
[TD]000[/TD]
[TD] [/TD]
[TD]TW123-50[/TD]
[TD="align: right"]277541[/TD]
[TD] [/TD]
[TD] [/TD]
[TD="align: right"]23.00[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]301[/TD]
[TD]88[/TD]
[TD]4155[/TD]
[TD] [/TD]
[TD]MRPXX220[/TD]
[TD]000[/TD]
[TD]000[/TD]
[TD][/TD]
[TD]TW2200-81[/TD]
[TD="align: right"]277469[/TD]
[TD][/TD]
[TD] [/TD]
[TD="align: right"]18.40[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]301[/TD]
[TD]88[/TD]
[TD]4155[/TD]
[TD] [/TD]
[TD]MRPXX220[/TD]
[TD]000[/TD]
[TD]000[/TD]
[TD] [/TD]
[TD]TW2200-81[/TD]
[TD="align: right"]277519[/TD]
[TD][/TD]
[TD] [/TD]
[TD="align: right"]18.40[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]301[/TD]
[TD]88[/TD]
[TD]4155[/TD]
[TD] [/TD]
[TD]MRPXX221[/TD]
[TD]000[/TD]
[TD]000[/TD]
[TD] [/TD]
[TD]TW221-395[/TD]
[TD="align: right"]277542[/TD]
[TD][/TD]
[TD] [/TD]
[TD="align: right"]59.80[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]301[/TD]
[TD]88[/TD]
[TD]4155[/TD]
[TD] [/TD]
[TD]MRPXX409[/TD]
[TD]000[/TD]
[TD]000[/TD]
[TD] [/TD]
[TD]TW409-74[/TD]
[TD="align: right"]277493[/TD]
[TD][/TD]
[TD] [/TD]
[TD="align: right"]36.80[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]301[/TD]
[TD]88[/TD]
[TD]4155[/TD]
[TD] [/TD]
[TD]MRPXX409[/TD]
[TD]000[/TD]
[TD]000[/TD]
[TD][/TD]
[TD]TW409-74[/TD]
[TD="align: right"]277500[/TD]
[TD][/TD]
[TD] [/TD]
[TD="align: right"]140.76[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]301[/TD]
[TD]88[/TD]
[TD]4155[/TD]
[TD] [/TD]
[TD]MRPXX409[/TD]
[TD]000[/TD]
[TD]000[/TD]
[TD][/TD]
[TD]TW409-74[/TD]
[TD="align: right"]277511[/TD]
[TD][/TD]
[TD] [/TD]
[TD="align: right"]36.80[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
Hello everyone,

I want to automate a copy and paste. For example id to be able to repaste the bolded values in the cells directly 1 below. I was thinking of using something like this, but I am unsure what would come afterwards as I am a novice.

Sub try()
Dim c As Range
For Each c In Range("J1:K80")
If c.Value Like "*TW747*" Or c.Value Like "*TW691*" Or c.Value Like "*TW2200*" Or c.Value Like "*TW750*" Or c.Value Like "*TW409*" Or c.Value Like "*TW742*" Then
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I'm very new to all this too, but I've had a crack! I've made the assumption that blank rows you have in your table aren't already there in the dataset, but should be added by the macro, and only where there is a match with your conditions. I've added comments through the code to explain each line.

Code:
Sub try()

Dim c(1 To 6) As String
Dim i As Integer
Dim j As Integer
Dim lastRow As Integer


c(1) = ("*TW747*")
c(2) = ("*TW691*")
c(3) = ("*TW2200*")
c(4) = ("*TW750*")
c(5) = ("*TW409*")
c(6) = ("*TW742*")


i = 1


With ActiveSheet
        ' Find the row that the last data line is in
    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
    
    ' Loop through the data to the last row
Do While i <= lastRow
        ' Loop through the string conditions (UBound(c) giving the size of the array)
    For j = 1 To UBound(c)
            ' If there's a match, then...
        If Cells(i, 10).Value Like c(j) Then
                ' Insert blank row beneath the current one
            Cells(i + 1, 10).EntireRow.Insert shift:=xlDown
                ' Copy the values from the matching row into the blank one
            Range(Cells(i + 1, 10), Cells(i + 1, 11)).Value = Range(Cells(i, 10), Cells(i, 11)).Value
                ' Adjust loop values to account for the additional row
            lastRow = lastRow + 1
            i = i + 1
            Exit For
        End If
    Next j
    
    i = i + 1
Loop


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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