Excel cut-paste

Theglyde

New Member
Joined
May 29, 2020
Messages
34
Office Version
  1. 365
Platform
  1. Windows
I have two different excel workbook

one is work in progress, other is archived work that is done

practically, I want to open

« Work »
with my cursor select 10rows in a row, when highlighted

click on button with macro that opens « Archived »
Cuts the rows out of « work » that I selected before clicking button and paste then at the end of column A of Archived. I have all coding that opens, that saves and closes... I have also code that will find last row. What I am missing is how tu cut out the info I have selected before the macro button and paste it
 
I am outside now and reading your post in mobile. When I get chance, I will look into it and give you a working solution.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
no worries... Again very appreciative and happy to have found your help. I love that I saw this. I do this code in so many more lines usually seperate codes and then us a sub to Call mutliple macro’s but this in one shot so much best

meaning I open. then I do the copy paste, then I do the save and close, but all separated... much longer lol
 
Upvote 0
Hello
Try this:
VBA Code:
Sub cut()
    Dim lastrow As Long
    Dim OpenBook As Workbook
    Application.CutCopyMode = False
    Application.ScreenUpdating = False

    Selection.Copy
    Set OpenBook = Workbooks.Open("myBook.xlsm")
    lastrow = Range("A" & Rows.Count).End(xlUp).Row + 1
    Range("A" & lastrow).PasteSpecial xlPasteAll
    OpenBook.Close SaveChanges:=True
    Selection.Delete
    
    Application.ScreenUpdating = True
    Application.CutCopyMode = True
End Sub
 
Upvote 0
The above code should work perfectly.
If you want to select entire row and copy that then we can check if entire row(s) is/are selected.
If entire row(s) is/are not selected, then the below code will display a message asking user to select at least one entire row. The data will only be copied if entire row(s) is/are selected.
Here is the code:
VBA Code:
Sub cut()
    Dim lastrow As Long
    Dim OpenBook As Workbook
    Dim NumCols As Long
    Dim Answer As VbMsgBoxResult
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = False
    
    NumCols = Selection.Columns.Count
    If NumCols <> 16384 Then
        Answer = MsgBox("It looks like you are not selecting entire row(s)." & vbNewLine & _
        "Please select at least one entire row to proceed.", vbOKOnly, "Selection Invalid...")
        Application.ScreenUpdating = True
        Application.CutCopyMode = True
        Exit Sub
    Else
        Selection.Copy
        Set OpenBook = Workbooks.Open("C:\Users\sushi\Documents\myBook.xlsm")
        lastrow = Range("A" & Rows.Count).End(xlUp).Row + 1
        Range("A" & lastrow).PasteSpecial xlPasteAll
        OpenBook.Close SaveChanges:=True
        Selection.Delete
    End If
    Application.ScreenUpdating = True
    Application.CutCopyMode = True
End Sub
 
Upvote 0
Hello
Try this:
VBA Code:
Sub cut()
    Dim lastrow As Long
    Dim OpenBook As Workbook
    Application.CutCopyMode = False
    Application.ScreenUpdating = False

    Selection.Copy
    Set OpenBook = Workbooks.Open("myBook.xlsm")
    lastrow = Range("A" & Rows.Count).End(xlUp).Row + 1
    Range("A" & lastrow).PasteSpecial xlPasteAll
    OpenBook.Close SaveChanges:=True
    Selection.Delete
   
    Application.ScreenUpdating = True
    Application.CutCopyMode = True
End Sub


OMG ? you are so amazing!!! been on this for 6hrs atlease... tried so many version. So many were close but this one is working... Thank you
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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