Copy Rows from other Sheet

adelspark

New Member
Joined
Nov 25, 2010
Messages
13
Hello All,

I thought I'd be smart and create a quick recorded macro to select/copy some rows in sheet 'A' and then paste them into sheet 'B' and sort. It wasn't so quick and easy, because it fails at the Rows("6:220").Select line when it runs. Strange, because that's the way it recorded it (see below).

Any thoughts?

Thanks in Advance


Private Sub Worksheet_Activate()
'
Sheets("Grouped Register").Select
Rows("6:220").Select
Selection.Copy
Sheets("Numerical Register").Select
Range("A6").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Numerical Register").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Numerical Register").Sort.SortFields.Add Key:= _
Range("C6:C220"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Numerical Register").Sort
.SetRange Range("B6:N220")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A6").Select
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try:
Code:
Private Sub Worksheet_Activate()
'
Sheets("Grouped Register").Rows("6:220").Copy Destination:=Sheets("Numerical Register").Range("A6")
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Numerical Register").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Numerical Register").Sort.SortFields.Add Key:= _
Range("C6:C220"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Numerical Register").Sort
.SetRange Range("B6:N220")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A6").Select
End Sub
 
Upvote 0
A big thank you from Australia, Machopicho; you even re-wrote the entire code for me and it works beautifully! I see where I went wrong now.

By the way, that thumbnail photo of me doing 'via ferrata' was taken two months ago only about 100km from Varese. Even more bizarre is that next year we are travelling to Machu Picchu. It's a small but surprising world we live in.

Thanks again ;)
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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