98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Cut rows and paste to another worksheet
Cut rows and paste to another worksheet
Resolved · Low Priority · Version 2007
Elena has attended:
Excel VBA Intro Intermediate course
Cut rows and paste to another worksheet
Hi,
I have a table:
Name Price date Archive
Xxx £20 08/01/13 ready
Yyy £35 12/02/13 no
Zzz £55 14/02/13 ready
I would like to be able to cut ready to archive rows and paste them to a different page. Can somebody suggest a code please because everytime I do it I just overwrite previousely archived data and I would like to paste it into empty cells?
Kind regards,
Elena
RE: Cut rows and paste to another worksheet
Hi Elena
Thanks for getting in touch. I assume you have the copy and paste procedure working correctly, and you are looking to just find the next available empty cell. In which case, assuming you have just copied the data and navigated to your archive sheet, something along these lines will do that:
Range("A1").Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
This is a simplistic but perfectly practical method to find the next empty cell in column A. If column A has gaps in the data you will need to modify accordingly.
If you wanted to recreate these stages by recording, with Relative References turned on you would go to cell A1, press CTRL + Down, then down one more cell.
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
RE: Cut rows and paste to another worksheet
Hi Gary,
Thank you for your quick respond. I am so very new to VBA so I am doing something wrong and my code is not working. Now I am stuck on ((Range("A1").Selection.End(xlDown).Select)). For some reason VBA didn't like it.
Thank you for your help.
Sub Macro1()
Sheets("Data Entry Sheet").Select
Range("A3").CurrentRegion.Name = "Filter"
Range("Filter").AutoFilter Field:=38, Criteria1:="Ready"
Range("A2").CurrentRegion.Offset(1, 0).Cut
Sheets("ARCHIVE").Select
Range("A1").Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.PasteSpecial
Sheets("Data Entry Sheet").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter
End Sub
RE: Cut rows and paste to another worksheet
Hi Elena
Thanks for your reply. My apologies, there was an error in one of the lines I gave you - it has two objects in.
Range("A1").Selection.End(xlDown).Select
Should be
Range("A1").End(xlDown).Select
I hope that fixes it.
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Will be marked as resolved in 5 days
Notice: This is an automated message. Due to inactivity, this forum post will be marked as 'resolved' if there are no further responses in the next 5 days.
RE: Cut rows and paste to another worksheet
Hi Gary,
I am still trying to make my macro working. Everything seems to be OK (when I do F8) untill I come to the line "Delete empty rows". It looks like nothing happening at all, I have to restart Excel as program is not responding.
Kiund regards,
Elena
Sub Archive()
'to stop screen flickering
Application.ScreenUpdating = False
'Selecting Sheet
Sheets("Data Entry Sheet").Select
'All rows to filter
Range("A3").CurrentRegion.Name = "Filter"
'Selecting ready to archive rows
Range("Filter").AutoFilter Field:=38, Criteria1:="Ready to Archive"
'Cutting ready to archive rows
Range("A3:AL" & Range("B65536").End(xlUp).Row).Select
Selection.Copy
'Paste to Archive sheet without switching sheets. I used column B as this is always seems to be populated, so will always go to the last record
Sheets("ARCHIVE").Range("B65536").End(xlUp).Offset(1, -1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'To delete empty rows
Selection.Delete Shift:=xlUp
Selection.AutoFilter
Application.ScreenUpdating = True
End Sub
RE: Cut rows and paste to another worksheet
Hi Elena
I've tried your code out on a test workbook and it worked fine (the only downside is the header row gets deleted). It certainly didn't hang or crash.
The only circumstance that might break it is if the Autofilter action returns no rows? beyond that I'm struggling to see what could be a problem.
If you're still having issues, please feel free to email me the file at gary@stl-training.co.uk
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Printing spreadsheets without opening them firstHere's a fast way of printing a spreadsheet from Windows Explorer/My Computer. |