Sheets("Tues").Range("A1").Select
Range(Selection, Selection.SpecialCells(xlCellTypeLastCell)).Select
Where does this name the range ?
Next time I'll read the post :)
Sheets("data").Range("A1").Select
ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:=Range(Selection, Selection.SpecialCells(xlCellTypeLastCell))
Thank you for responding.
the code works, however, if the data range changes and the macro re-run(smaller) the range does not change. If it is larger it expands.
I would like to have it adjust either way.
Any sugegstions ?
PJ
Yes, the "LastCell" function is a bit quirky to say the least, but I wasn't sure if it would be a problem from looking at your original question. If you really want this done right, here's an adaptation of code that I found that works very well.
Sub setRange()
Dim LastRow, LastCol, LastCell
'Removes runtime error if worksheet is blank
On Error Resume Next
With Worksheets("Tues")
LastRow = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
LastCol = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
End With
Set LastCell = Cells(LastRow, LastCol)
ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:=Range("A1", LastCell)
End Sub