Random Sorting

  • Thread starter Thread starter Megaman
  • Start date Start date
M

Megaman

Can anyone help?

I have a sheet with the following data:

Item, Price1, Price2, Price3, Price4,


I want to sort the prices for each item randomly but not sorting the whole
col together but sorting row for row eg.

Item, Price3, Price2, Price4, Price1,

Item, Price2, Price4, Price3, Price1,

Item, Price1, Price2, Price3, Price4,

And so on down the rows.

I can sort the whole col. by using a rnd. number but that wont help as my
prices are from low to high and I need them to be scattered but still
relating
to the correct items.

Many thanks in advance,

Des
 
Hi,

pls run the enclosed macro on an empty sheet. (The macro is recorded
'cause i do not know the functions in english, you only need the
resulting formulas in the sheet.)

columns A to E show what you want, the rest is used for construction.
The prices will be sorted on every change you make in the sheet.

columns F to I show random numbers (random*random = very unlikely to
get the same number twice (which would mean same rank)). columns J to M
show the rank of the random numbers, columns O to R are your 4 prices.

read help to rank(), rand(), offset() functions.

regards

arno



Sub Makro1()
Cells(7, 1).Select
ActiveCell.FormulaR1C1 = "item"
Range("F7").Select
ActiveCell.FormulaR1C1 = "=RAND()*RAND()"
Range("G7").Select
ActiveCell.FormulaR1C1 = "=RAND()*RAND()"
Range("H7").Select
ActiveCell.FormulaR1C1 = "=RAND()*RAND()"
Range("I7").Select
ActiveCell.FormulaR1C1 = "=RAND()*RAND()"
Range("J7").Select
ActiveCell.FormulaR1C1 = "=RANK(RC[-4],R7C6:R7C9)"
Range("K7").Select
ActiveCell.FormulaR1C1 = "=RANK(RC[-4],R7C6:R7C9)"
Range("L7").Select
ActiveCell.FormulaR1C1 = "=RANK(RC[-4],R7C6:R7C9)"
Range("L8").Select
ActiveWindow.SmallScroll ToRight:=1
Range("M7").Select
ActiveCell.FormulaR1C1 = "=RANK(RC[-4],R7C6:R7C9)"
Range("M8").Select
ActiveWindow.SmallScroll ToRight:=6
Range("O7").Select
ActiveCell.FormulaR1C1 = "a"
Range("P7").Select
ActiveCell.FormulaR1C1 = "b"
Range("Q7").Select
ActiveCell.FormulaR1C1 = "c"
Range("R7").Select
ActiveCell.FormulaR1C1 = "d"
Range("R8").Select
ActiveWindow.LargeScroll ToRight:=-1
Range("B7").Select
ActiveCell.FormulaR1C1 = "=OFFSET(RC14,0,RC[8],1,1)"
Range("C7").Select
ActiveCell.FormulaR1C1 = "=OFFSET(RC14,0,RC[8],1,1)"
Range("D7").Select
ActiveCell.FormulaR1C1 = "=OFFSET(RC14,0,RC[8],1,1)"
Range("E7").Select
ActiveCell.FormulaR1C1 = "=OFFSET(RC14,0,RC[8],1,1)"
Range("E8").Select
End Sub
 
Thank's guy's for the prompt replys,

I've solved my problem using sulprobil's function.

Many thank's once again for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top