Help with Joining Ranges?

Sthrncali

Board Regular
Joined
Apr 1, 2011
Messages
226
Ok so here is what I am trying to do efficiently...

I have a worksheet with 75 rows of data and I want to insert a RANK into a column via VBA.

The issue is I want to rank Rows 1, 7, 14, 21, 28, 35, and 42 as a group. Then I want to rank rows 2-6, 8-13, 15-20, 22-27, 29-34, and 36-41 as a group.

So the first ranking would have ranks 1- 7 and the second group would have ranks 1-35.

Does that make sense?

I can insert the values into a different spreadsheet and rank them there, then VLOOKUP that table to get the values back to the original, but I thought using a JOIN might be more efficient - problem is I don't have much experience joining ranges..

Any help? :)
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,850
Hi

I'm not sure I understood correctly but, with your values in column A, this code inserts the formulas in column B:

Code:
Sub WrRank()
Dim r As Range
 
Set r = Range("$A$1,$A$7,$A$14,$A$21,$A$28,$A$35,$A$42")
r.Offset(0, 1).FormulaR1C1 = "=RANK(RC[-1],(" & r.Address(ReferenceStyle:=xlR1C1) & "))"
Set r = Range("$A$2:$A$6,$A$8:$A$13,$A$15:$A$20,$A$22:$A$27,$A$29:$A$34,$A$36:$A$41")
r.Offset(0, 1).FormulaR1C1 = "=RANK(RC[-1],(" & r.Address(ReferenceStyle:=xlR1C1) & "))"
End Sub
 

CWatts

Well-known Member
Joined
Jan 22, 2010
Messages
701
You can use worksheet functions to do it as well.

If you CTRL click all of the cells that you want (1, 7, 14, 21, 28, 35, and 42), you can then set those cells as a named range.

In the cells in row 1, 7, 14 etc, you can use the rank function and it will only rank those rows.

=RANK(A1,YourNamedRange,1)
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,850
Hi CWatts

You can use worksheet functions to do it as well.

Remark: that's what I'm doing. I'm just writing them with vba instead of directly in the cells because Sthrncali asked. :)
 

CWatts

Well-known Member
Joined
Jan 22, 2010
Messages
701
I so totally missed the "via VBA" part of the original post... :eek:
 

Watch MrExcel Video

Forum statistics

Threads
1,109,367
Messages
5,528,271
Members
409,813
Latest member
robyrux

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top