VBA delete row after cut-&-paste

bazzinga

New Member
Joined
Dec 5, 2023
Messages
12
Office Version
  1. 2021
Platform
  1. Windows
Hello,

Problem: I would like the row getting cut to be deleted automatically after being cut&paste in order to avoid lines without formulas. (Or let me know if there's any other alternative)

Context: I am using a spreadsheet that is shared with many people and on a daily basis rows gets moved around. I am trying to implement a new excel that includes a vlookup formula and don't want running cases where a line won't have a formula because it was cut to somewhere else.

Thank You,
B.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Not sure if I am allowed to bump a thread - just wondering if anyone know a solution for this
 
Upvote 0
How about showing us an example of your data and a mocked up solution. Provide the criteria for removing a row. Please use XL2BB function to upload samples. Do not post pictures as they cannot be manipulated. A good sample is 10-15 recocrds.
 
Upvote 0
How about showing us an example of your data and a mocked up solution. Provide the criteria for removing a row. Please use XL2BB function to upload samples. Do not post pictures as they cannot be manipulated. A good sample is 10-15 recocrds.
Hi, not sure what to show. I want a line to be deleted automatically if I were to cut it and paste somewhere else, so there won't be lines without the formula.

So for example if I were to cut line 5 and paste it on line 25, I want line 5 to be deleted, so it doesn't get used and no populate the data.


Cell Formulas
RangeFormula
D2:D17D2=IFNA(VLOOKUP($F:$F,'[sales order 2024.xlsx]Invoice No.'!$A:$D,4,FALSE),"")
 
Upvote 0
I can't see a way to do this without VBA.

VBA Code:
Option Explicit

Sub DeleteRow()
    Dim s1 As Worksheet, s2 As Worksheet
    Dim x As Long, y As Long
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    Application.ScreenUpdating = False
    x = InputBox("What row number to cut?")
    y = InputBox("What row number to paste?")
    s1.Range("A" & x).EntireRow.Cut s2.Range("A" & y)
    s1.Range("A" & x).EntireRow.Delete
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "Action Complete"

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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