VBA for Cut, move, paste, delete rows

RForster6

New Member
Joined
Jul 30, 2020
Messages
6
Office Version
  1. 365
Good day,

I have an inventory report that is about 20 years old that is used as a count sheet. It does what it should but I need to make it into a data sheet for Vlookups when inventory time rolls around.
The report has sections for each Department. Each department has sections for location like an area or room number.
The data header row has in F18 Asset Type / Description.
The records are like F20 Asset Type, then F21 has the Description. The have a similar field length so I can see why the report was designed this way.
I have inserted a colum G so I can move the description from line 21 to line 20. Then I can select rows 21 and 22 and delete.
I recorded a macro and moved my data twice:
Sub Macro1()

' Macro1 Macro
'
Range("F21").Select
Selection.Copy
Range("G20").Select
ActiveSheet.Paste
Rows("21:22").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("F22").Select
Selection.Copy
Range("G21").Select
ActiveSheet.Paste
End Sub

What I really want is to copy the cell I am in, move up a row and over one column and paste. Then select the next two rows and delete. My cursor should end up in the next asset description. I don't want to use cell references because they will change. I want to use the cell selection and then subtract and add rows and columns

Appreciate any help.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try the code below (test on a copy of your data) and let me know if it is doing anything incorrectly

VBA Code:
Sub MoveCopy()
    'What I really want is to copy the cell I am in,
    'move up a row and over one column and paste.
    'Then select the next two rows and delete.
    'My cursor should end up in the next asset description.

    ActiveCell.Copy ActiveCell.Offset(-1, 1)
    ActiveCell.Resize(2).EntireRow.Delete
End Sub
 
Upvote 0
Thank you! Works perfectly. I added "ActiveWorkbook.Save" to your code.
My cursor ends up in the Asset field rather than the next description. How would I move it down a row? ActiveCell.Offset(1,0)?
 
Upvote 0
Yes. This was just for capital inventory so it was quick. The main inventory sheet is 4k+ lines.
The next step in this would be a Do While for the next line which is completely blank. But at the end of each section there is not a blank line. It's the header for the next Department or Department section.
The start of the header: Ax is Location: then Bx is the Department name but it is merged out to K. And for now I want to leave the sections there.
Maybe I will look at the loop stuff tomorrow. Super happy learnig these commands because they will be useful in the future as well.
 
Upvote 0

Forum statistics

Threads
1,224,261
Messages
6,177,491
Members
452,782
Latest member
ZCapitao

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