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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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