VBA create array of row numbers in order of cell contents

M0Dark

New Member
Joined
Feb 19, 2014
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a sheet which contains values in cells B5 - B17, I need to create an array of the row numbers in order of the cell values in ascending order, I need to ignore any blanks too. This cannot be done on the sheet because of the way the workbook functions.
e.g column B5 down could contain:
Cell Value or
B5 0 50
B6 1 55
B7 2 65
B8 3 100
B9 4 08
B10 5 76
B11 6 22
B12 "" 33
B13 "" 42
B14 "" 66
B15 "" 12
B16 "" 10

I then need an array that has the row numbers in order of the cell values so:
Index Value Or
1 5 9
2 6 16
3 7 15
4 8 11
5 9 12
6 10 13
7 11 5
8 N/A 6
9 N/A 7
10 N/A 14
11 N/A 10
12 N/A 8

What is the simplest method to do this please?
Once I have the row numbers I need to put the values from the array (-4 in each case) in order into the sheet in column A, but I know how to do this part. As column A drives a large lookup table this then re-sorts the sheet and all related sheets into ascending order.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
85,067
Office Version
  1. 365
Platform
  1. Windows
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Also why can't you have a formula in col A that does exactly what you want?
 
Upvote 0

M0Dark

New Member
Joined
Feb 19, 2014
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Morning Fluff,

The data is a series of test points, I can't have a formula in column A because on the sheet column A has drop down menus which let the user select what order to put the test points in, this is needed because sometimes a different order is required, but most of the time Ascending is the preferred layout so I am trying to have it set the order ascending when the test values are imported from a CSV file.
When the test point number in a row of column A is changed the sheet looks up the corresponding test data and populates columns B to BI

Testbed New Jon.xlsm
AB
2Test PointFlow (SI)
3Q
4N/Am^3/s
510.00690
620.01385
730.02209
840.02838
950.02919
1060.03445
1170.04258
1280.00020
139 
1410 
1511 
1612 
Test Data Corrections
 
Upvote 0

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
85,067
Office Version
  1. 365
Platform
  1. Windows
Ok, how about
VBA Code:
Sub M0Dark()
   Dim Ary As Variant
   
   With Range("B5", Range("B" & Rows.Count).End(xlUp))
      Ary = Evaluate(Replace("sortby(filter(row(@)-4,@<>""""),filter(@,@<>""""))", "@", .Address))
   End With
   Range("A5").Resize(UBound(Ary)).Value = Ary
End Sub
 
Upvote 0
Solution

M0Dark

New Member
Joined
Feb 19, 2014
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Turns out I could just place an extra column on another sheet and use match & small to find the positions then use that to do the initial sort. Thanks anyway.
 
Upvote 0

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
85,067
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,195,664
Messages
6,011,023
Members
441,579
Latest member
satishrazdhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top