Hi as the last step in a process which has been invaluably helped along by this forum, the last step is to finish the macro with defining a named range for the data which has just been sorted. It needs to be variable to cope with any additions to the initial data. The attached code selects the data from named ranges and copies them to Sheet2. It then selects the present data and sorts by columnA. The step I need is to name this range as MOT_DATA. I tried recording the action and using the code but got lost when cell references changed to R1:C1(not used to this). Any help appreciated. TA Nigel
Option Explicit
Sub Macro1()
Dim Rng As Range
Sheets("Sheet2").Select
Columns("a:k").ClearContents
With Sheets("Sheet1")
Set Rng = .Range("walking_floor")
Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1, _
Rng.Columns.Count).Copy Sheets("Sheet2").Range("a1")
Set Rng = .Range("ejector")
Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1, _
Rng.Columns.Count).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Set Rng = .Range("flat")
Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1, _
Rng.Columns.Count).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Set Rng = .Range("tanker")
Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1, _
Rng.Columns.Count).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End With
With Sheets("Sheet2")
.Columns("B:B").Delete
Range("A1:B" & .Cells(.Rows.Count, "B").End(xlUp).Row).Select
Selection.Sort Key1:=Range("a1")
Range("A1:B" & .Cells(.Rows.Count, "B").End(xlUp).Row).Select
'Selection.ActiveWorkbook.Names.Add Name:="MOT_DATA", RefersToR1C1':=
'STUCK HERE WITH DEFINING THE VARIABLE NAMED RANGE
End With
End Sub
Bookmarks