Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default SpecialCells(xlLastCell) selects old data

Usedrange would give the same result for the farthest used cell as
xlLastCell. Gary makes the common mistake of assuming that A1 is in the
usedrange. While it may be, it isn't necessarily. Which to use (if you
have lost interest in the original issue), depends on what you want.

Also, like I said, the original problem is not circumvented with Usedrange.
You might want to do a bit more testing associated with your original
problem.

--
Regards,
Tom Ogilvy


" wrote:

Thanks to Both of you. Both methods work.

Gary''s Student wrote:
Your code does not select the last cell, it is selecting the whole range
between A1 and the last cell. If this is what you want to do then:

Sub SetData()
Worksheets("Data").Activate
ActiveSheet.UsedRange.Select
Selection.Name = "Data"
End Sub

will work just as well.
--
Gary's Student


" wrote:

I'm using the following code to select a all the data on a sheet and
assign it a named range

Sub SetData()

Worksheets("Data").Activate

'Select last cell in data range, give is a local name "Data"
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select

Selection.Name = "Data"

End Sub

I noticed that if I reduced the size of the data range and run the code
the updated range selection is not the new smaller range, but the old,
larger range. Its as if SpecialCells(xlLastCell) looks for the last
cell ever used, not necessarily the last cell in the range.

Is there a more appropriate method to use than SpecialCellc?

or

Is there a to scrub the unused cells so that SpecialCells(xlLastCell)
doesn't recognize them?

Thanks
Robert




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fully Qualifying - ActiveCell.SpecialCells(xlLastCell)).Select tmort[_14_] Excel Programming 3 July 26th 06 08:31 PM
specialcells(xlLastCell) and method global range error [email protected] Excel Programming 0 July 25th 06 09:51 PM
.Cells.SpecialCells(xlLastCell) Simon Shaw Excel Programming 8 May 5th 05 11:46 PM
SpecialCells(xlLastCell) José Ignacio Bella Excel Programming 12 January 9th 05 07:20 PM
.SpecialCells(xlLastCell).Select jim c. Excel Programming 3 October 3rd 03 04:02 PM


All times are GMT +1. The time now is 01:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"