Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create range based on value in column

Status
Not open for further replies.

Rzrbkpk

Technical User
Mar 24, 2004
84
0
0
US
I need to create a ranges for a data set that changes everytime a report is run. The columns are a consistent order and count. The range would be based on the value in column B. I can work with A1 or index format. Here's an example of the data:

A B C D
U.S. New York Albany 200
U.S. New York Buffalo 10
U.S. New York Binghamton 30
U.S. Georgia Savannah 15
U.S. Georgia Atlanta 500

So my range for New York would be (A1:D3) and for Georgia it would be (A4:D5).
 
hi,

That is not a best and accepted practice for range names.

Rather consider this standard practice
[tt]
Country State City Amount

U.S. New York Albany 200
U.S. New York Buffalo 10
U.S. New York Binghamton 30
U.S. Georgia Savannah 15
U.S. Georgia Atlanta 500
[/tt]
where each column is NAMED using the column heading, quite simply using Formulas > Defined Names > Create From Selection > Create names in TOP row

No VBA required!

Excel's lookup and aggregation formulas are designed to work with ranges like this.

faq68-1331
faq68-5184

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks for your response Skip. My apologies, the columns do have headers (actually the ones you indicated). The reason I'm using VBA is because my ultimate goal is to sort 20+ ranges by two other columns - Date(E) and Status(F) everytime the report is produced. The customer for the report is requesting that the report keep a non-sortable order (i.e. states in a specificied preference order) and then sorted by the other criteria within that grouping. I've managed to code the report to group all the states and produce them in the preferred order, but I can't figure out the date and status sort.
 
Well your original question and the example provided, has nothing to do with sorting!

Consequently, with the information you have provided, I fail to perceive your problem.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I'll repost with a more accurate description of what I'm trying to accomplish.
 
Just explain it here!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
It sounds like all you need for the macro is to copy all of the data from the sheet to a clean sheet and then perform a SORT. The SORT would have a custom list for the City, and then by Status and Date (depending on how you want things grouped).

Alternately, you could apply FILTERS and possibly use the SUBTOTAL button. This might achieve a lot of the things you want with minimal coding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top