Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Naming variable range selected by cursor movement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Merritt Sakata - 29 May 2008 10:11 GMT
following code via macro recorder is intended to create a named database
range "Format_all" via cursor movement selection and then to format for
printing uisng data sort commands. But I need to eliminate fixed range
definition since the number of rows of data needs to be able to change freely
with the cursor selection.

Can you help?  

Sub Format_All()
'
' Format_All Macro
' Format All Records for Printing
'

'
   Application.Goto Reference:="Format_Start"
   Selection.End(xlDown).Select
   Selection.End(xlToLeft).Select
   Range("A1").Select
   Range(Selection, Selection.End(xlUp)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   Range(Selection, Selection.End(xlToRight)).Select
   ActiveWorkbook.Names.Add Name:="FORMAT_ALL", RefersToR1C1:="r9c1:R936C43"
   ActiveWorkbook.Names("Format_all").Comment = ""
   ActiveWorkbook.Worksheets("ESTIMATE").Sort.SortFields.Clear
   ActiveWorkbook.Worksheets("ESTIMATE").Sort.SortFields.Add Key:=Range( _
       "SortKey"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
       xlSortNormal
   ActiveWorkbook.Worksheets("ESTIMATE").Sort.SortFields.Add Key:=Range( _
       "Class"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
       xlSortNormal
   ActiveWorkbook.Worksheets("ESTIMATE").Sort.SortFields.Add Key:=Range( _
       "Description"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
       xlSortNormal
   With ActiveWorkbook.Worksheets("ESTIMATE").Sort
       .SetRange Range("Format_all")
       .Header = xlYes
       .MatchCase = False
       .Orientation = xlTopToBottom
       .SortMethod = xlPinYin
       .Apply
   End With
End Sub

thanks!
ward376 - 29 May 2008 10:32 GMT
ActiveWorkbook.Names.Add Name:="FORMAT_ALL", RefersTo:=Selection

Cliff Edwards
Bob Phillips - 29 May 2008 10:56 GMT
Selection.Name = "myRange"

Signature

---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

> following code via macro recorder is intended to create a named database
> range "Format_all" via cursor movement selection and then to format for
[quoted text clipped - 52 lines]
>
> thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.