Cut rows after cell value and insert above cell value

Deverti

Board Regular
Joined
Sep 5, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Im dealing with a slightly screwed up software export, what im trying to do right now is:

cut all rows with content below my case ("Total Ertrag") until the next empty row (cut without the empty row)
and paste it above my case

im having a hard time getting a clue as to how i should go about defining the cut range

any hints d be much appreciated ~

VBA Code:
Sub FixList()
   Dim vL As Range, vArea As Areas
   Set vArea = Range("A:A").SpecialCells(xlConstants).Areas
  
   For Each vL In Range("A1", Range("A" & Rows.Count).End(xlUp))
      Select Case vL.Value
         Case "Total Ertrag"
            vL.Offset(1).Select
            'vArea ?
            'vArea.EntireRow.Cut
            'vL.Offset(-1).Insert
      End Select
   Next vL
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

alright this should be publicly accessible now

i marked my areas of interest with colors. i need to cut the orange rows and paste it into the green row.
the example sheet is a fragment of the entire data and the number of rows within each orange area varies.
 
Upvote 0
Try:
VBA Code:
Sub MoveRows()
    Application.ScreenUpdating = False
    Dim fnd As Range, x As Long, y As Long, z As Long, cnt As Long
    cnt = WorksheetFunction.CountIf(Range("A:A"), "Total Ertrag")
    Set fnd = Range("A:A").Find("Total Ertrag", LookIn:=xlValues, lookat:=xlWhole)
    If Not fnd Is Nothing Then
        Do
            z = z + 1
            If fnd.Offset(1) <> "" Then
                x = fnd.CurrentRegion.Rows.Count
                y = fnd.CurrentRegion.Cells(2).Row
                Rows(y).EntireRow.Resize(x - 1).Cut
                Rows(fnd.Row).Insert
            End If
            Set fnd = Range("A:A").FindNext(fnd)
        Loop While z <= cnt
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,936
Messages
6,181,851
Members
453,068
Latest member
DCD1872

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