Excel - select a range by cell names; vba
Asked By cate
21-Nov-09 08:33 AM
I am trying to select X rows for a sort. The first and last rows have
a defined name, RSTART and RLAST. They look
like this in the Define Name dialog: ='MySheet'!$15:$15 ....
How do you select the rows using these names. Here is the macro output
of my best shot. I cannot figure out how to incorporate the second
name. Thank you.
Sub trythis()
Application.Goto Reference:="RSTART"
Rows("15:59").Select '<---- Held down shift key and selected
RLAST in cell address combo
Range("I15").Activate ' what is this?
Selection.Sort Key1:=Range("B15"), Order1:=xlDescending,
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
Excel
(1)
Macro
(1)
XlTopToBottom
(1)
XlSortNormal
(1)
ActiveSheet
(1)
SalesAid
(1)
XlGuess
(1)
TctedThank
(1)
Dave Peterson replied to cate
Most things that you do in excel do not need to have the objects (like ranges or
worksheets) selected first.
You could use code like:
Option Explicit
Sub trythis()
Dim wks As Worksheet
Dim myRng As Range
Set wks = ActiveSheet
With wks
'I like this first line--I find it more self-documenting
Set myRng = .Range(.Range("RStart"), .Range("RLast"))
'but you could use either of these, too.
'Set myRng = .Range("Rstart", "rlast")
'Set myRng = .Range("Rstart:Rlast")
End With
With myRng
.Sort Key1:=.Columns(2), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End Sub
--
Dave Peterson
cate replied to Dave Peterson
ges or
_
t
cted
Thank you. I always have problems with ranges. Sometimes I have
numbers, sometimes letters and, this time, names. Ahhhh.
Thanks again.
Don Guillett replied to cate
Sub sortnamedrange()
'NOT needed unless a different sheet
'Application.Goto Reference:="RSTART"
mc = 2 ' col B
fr = Range("rstart").Row
lr = Range("rlast").Row
Range(Cells(fr, mc), Cells(lr, mc)) _
.Sort Key1:=Cells(fr, mc), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com
sorting with a macro Excel why dont this work on other machine(pc) copied to same location(folder) same name and every thing. the only thing is I used excel 2002 and I dont know what ver the other pc has on it. Sub Sort_Drivers Sort_Drivers Macro ' Macro by Kelly ' ' Application.Run "'Points Tracker.xls'!UnprotectAll" Range("A4:AM104").Select Range("A4").Activate Selection.Sort Key1: = Range("A4"), Order1: = xlAscending, Header: = xlGuess, _ OrderCustom: = 1, MatchCase: = False, Orientation: = xlTopToBottom, _ DataOption1: = xlSortNormal Range("A4").Select Application.Run "'Points Tracker.xls'!ProtectAll" End Sub Sub Sort_Rank() ' ' Sort_Rank Macro ' Macro by Kelly ' ' Application.Run "'Points Tracker.xls'!UnprotectAll" Range("A4:AM104").Select Range("AM4").Activate
Using symbolic in Excel Macro Excel Hi, I have a numeric value x representing the number of rows. I would like do this? Currently: Range("BE1:BE179").Select Would like: Range("BE1:BEx").Select Thanks, Bob Excel Programming Discussions Range (1) Windows (1) Workbooks (1) Sort (1) Application (1) Excel (1) Sheets (1) Close. But, WHY select? x = 22 'or 'x = range("a2").value Range Guillett SalesAid Software dguillett1@austin.rr.com Hi Don, When I was manually recording the macro, I selected the 1st through row 179 for column BE. The macro provided me with the code and the reference to .select . Now I am trying to for the suggestion. I will give it a try. Regards, Bob Don, Here is the macro code. I am pretty new at this as you can tell. I would appreciate any
Macro Excel 2003 Excel Big picture: I want to create a budget (with a macro) from an Excel file I receive from another department. I would like to save a blank budget file where I copy the worksheet I recieve into a "blank budget file" and activate the macro to create the budget. What I receive to convert (project file): This project file has to copy the worksheet from the project file into the blank budget file where the macro will pull only the information I am interested in from the project worksheet and puts additional information. Thanks in advance for reading my dilemma and any help is greatly appreciated. Excel Programming Discussions Range (1) Sheets (1) VLOOKUP (1) ISERROR (1) Application (1) SUM (1) WorksheetFunction
How to build a macro to sort data on every worksheet in EXcel? Excel I was trying to build a macro to sort data on every worksheet within Excel 2007. However, after recording the macro, the macro seems to only refer to the original worksheet. The macro does not work in other worksheet. Here is the sequence I used: 1. Start recording
Different Results from the Same Macro Excel Hello: At the end of this posting, I have VBA code for a macro that I created. This macro was created in Excel 2007 macro. What's puzzling me is that this macro gives different results everytime that it is used. It is run against the same set I do not understand why it is producing different data in the spreadsheet. The attached macro code "runs against data" in a spreadsheet in order to generate another spreadsheet. Different results