hi all, i have values in column and i want to generate 5 value for random and without duplicate when i click on button with vba, my example file :
thanks in advanced,,,,,sorry for my poor english.
hi all, i have values in column and i want to generate 5 value for random and without duplicate when i click on button with vba, my example file :
thanks in advanced,,,,,sorry for my poor english.
Sub Test() Set r = ActiveSheet.UsedRange.Columns(1) r.Copy r.Offset(, 2) r.Offset(, 2).SpecialCells(2).Offset(, 1).Formula = "=Rand()" Range("C:D").Sort Key1:=Range("D:D"), Order1:=xlAscending, Header:=xlNo Range("C6:D" & Rows.Count).ClearContents Range("D:D").ClearContents End Sub
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
To avoid reporting duplicates, I think you need to add the marked line.
I added the .ScreenUpdating=False because the flashing was annoying me
Option Explicit Sub Test1() Dim R As Range Application.ScreenUpdating = False Set R = ActiveSheet.UsedRange.Columns(1) R.Copy R.Offset(, 2) R.Offset(, 2).SpecialCells(2).Offset(, 1).Formula = "=Rand()" Range("C:D").Sort Key1:=Range("D:D"), Order1:=xlAscending, Header:=xlNo 'added Range("C:D").RemoveDuplicates Columns:=1, Header:=xlNo Range("C6:D" & Rows.Count).ClearContents Range("D:D").ClearContents Application.ScreenUpdating = True End Sub
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
thank you very much for your help.