Macro to insert array formula

konradz

New Member
Joined
May 29, 2012
Messages
8
Hi,

I'm working on a simple macro that would insert a simple sorting formula depending on the user selection. I took few lines of code to call a form enabling the range selection. I would like to pass the selection value from the form as the tbl para
meter in this formula:
Code:
=INDEX(tbl, MIN(IF(SMALL(COUNTIF(tbl, "<"&tbl),  ROWS($B$8:B8))=COUNTIF(tbl, "<"&tbl), ROW(tbl)-MIN(ROW(tbl))+1)),  MATCH(SMALL(COUNTIF(tbl, "<"&tbl), ROWS($B$8:B8)), COUNTIF(tbl,  "<"&INDEX(tbl, MIN(IF(SMALL(COUNTIF(tbl, "<"&tbl),  ROWS($B$8:B8))=COUNTIF(tbl, "<"&tbl), ROW(tbl)-MIN(ROW(tbl))+1)),  , 1)), 0), 1)
In addition, I would like to replace the $B$8:B8, with the above cell from the currently selected cell. So in a word four things have to happen:

  1. User clicks on the button and form to select the range appears
  2. The selected range is passed and replaces the tbl range in the formula above
  3. $B$8:B8 - changes to the cell above the selected cell (if top cell is active error message appears)
  4. Index array formula is inserted to the currently active cell

I often use this sorting formula and it would be easier to develop a macro inserting the formula automatically instead of inserting it manually all the time. I will greatly appreciate any help.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,215,532
Messages
6,125,358
Members
449,221
Latest member
chriscavsib

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
Back
Top