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

CountryCityDollar
NotesHello
CountryCityDollar
CountryCityDollar
NotesHello

<tbody>
</tbody>



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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi All, I`m looking trying to code my script for Excel,
I have a Data set that looks like this

CountryCityDollar
NotesHello
CountryCityDollar
CountryCityDollar
NotesHello

<tbody>
</tbody>

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
CountryCityDollar
NotesHello
CountryCityDollar
CountryCityDollar
NotesHello

<tbody>
</tbody>


After

CountryCityDollarNotesHello
CountryCityDollar
CountryCityDollarNotesHello

<tbody>
</tbody>

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

Forum statistics

Threads
1,216,761
Messages
6,132,565
Members
449,736
Latest member
anthx

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