Macro to Move

WillPeters

New Member
Joined
Oct 23, 2023
Messages
9
Office Version
  1. 2021
Platform
  1. Windows
Hello all,

I need help with a macro to move rows/cells, similar to deleting a row and shifting everything up, but not, because there is important content outside of the table that should remain static. So, to clarify:

The area I'm speaking of is from D4 to F15 only. Within this area, if there is row that has an empty E cell, the contents in the rows below should shift upwards in unison, maintaining its alignment/pairing with each other until there is no empty E cells above the rows (yes, overwriting content in D and F as long as E is empty). And keep in mind that the contents outside of D4 to F15 should remain still with no movement. Thank you in advance for your input and guidance!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try:
VBA Code:
Sub DeleteCells()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("E4:E15")
        If rng = "" Then
            Range("D" & rng.Row).Resize(, 3).Delete shift:=xlUp
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Sub DeleteCells()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("E4:E15")
        If rng = "" Then
            Range("D" & rng.Row).Resize(, 3).Delete shift:=xlUp
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
Thank you! The macro worked as expected. But it shifted the contents below D14:F14 up as well. I need those below D14:F14 to stay put. Any way we can only limit the moving cells to D4:F15?
 
Upvote 0
Try:
VBA Code:
Sub DeleteCells()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("E4:E15")
        If rng = "" Then
            Range("D" & rng.Row + 1 & ":F15").Cut Range("D" & rng.Row)
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Sub DeleteCells()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("E4:E15")
        If rng = "" Then
            Range("D" & rng.Row + 1 & ":F15").Cut Range("D" & rng.Row)
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
Thank you! Appreciate you!
 
Upvote 0
You are very welcome. :)
Uh oh, one last question, my cells are formatted to have white borders. After running the macro, the gray lines become visible. Any way we can have the shift upwards but retain the white border formatting? Almost like a clear content
 
Upvote 0
Try:
VBA Code:
Sub DeleteCells()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("E4:E15")
        If rng = "" Then
            Range("D" & rng.Row + 1 & ":F15").Cut Range("D" & rng.Row)
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
Uh oh, one last question, my cells are formatted to have white borders. After running the macro, the gray lines become visible and formulas using that data are impacted. Any way we can have the shift upwards but retain the white border formatting and does not impact formulas linked to the cells? Almost like a clear content
 
Upvote 0
It would be easier to help and test possible solutions if 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

Forum statistics

Threads
1,215,107
Messages
6,123,126
Members
449,097
Latest member
mlckr

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