VBA cutting from a fiel and pasting to the line above and after

Knovi

New Member
Joined
Dec 19, 2017
Messages
2
Hi All, I`m looking trying to code my script for Excel,
I have a Data set that looks like this

[TABLE="width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



What I want to do is go through all my data. If I find something called Notes Cut this and the field next to it(hello) and paste it at the end of Dollar amount from the previous line.


Code:
Sub test1()
Dim rcnt As Long
rcnt = Worksheets("Feuil1").Range("C" & Rows.Count).End(xlUp).Row


For i = 1 To rcnt


If Range("C" & i).Value = "Notes" Then
    Range("C" & i, "D" & i).Cut
    Range("M" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
      
   
   End If
Next i


Application.CutCopyMode = False
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi All, I`m looking trying to code my script for Excel,
I have a Data set that looks like this

[TABLE="width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

What I want to do is go through all my data. If I find something called Notes Cut this and the field next to it(hello) and paste it at the end of Dollar amount from the previous line.

I think is would be helpful if you posted the final result that you want for the example above.
 
Upvote 0
Try:
Code:
Sub test1()
    Dim rcnt As Long
    rcnt = Worksheets("Feuil1").Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To rcnt
        If Range("C" & i).Value = "Notes" Then
            Range("C" & i & ":D" & i).Cut Range("M" & i - 1)
        End If
    Next i
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Very true.
Before
[TABLE="width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


After

[TABLE="width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country[/TD]
[TD]City[/TD]
[TD]Dollar[/TD]
[TD]Notes[/TD]
[TD]Hello[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

This is in a report that will keep the same formating every month, it has over 1500 lines
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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