How to insert data in ascending order into an array in vba excel?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to convert a column number (eg. 127) into an excel column (eg. AA)CopyOrigin on Insert in Excel VBADifference between Visual Basic 6.0 and VBAIs there a way to crack the password on an Excel VBA Project?Excel to CSV with UTF8 encodingHow to avoid using Select in Excel VBAVBA Code to sort an Excel Column in Ascending Order and Expand Selection?Merge two lists in Excel in ascending or descending ordervba code to insert row and data in ascending order

Why is it that I can sometimes guess the next note?

Need help understanding what a natural log transformation is actually doing and why specific transformations are required for linear regression

What if a revenant (monster) gains fire resistance?

How do you make your own symbol when Detexify fails?

Using substitution ciphers to generate new alphabets in a novel

What is Cash Advance APR?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Why should universal income be universal?

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

How to fade a semiplane defined by line?

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?

Mimic lecturing on blackboard, facing audience

Angel of Condemnation - Exile creature with second ability

Creepy dinosaur pc game identification

How to explain what's wrong with this application of the chain rule?

Fear of getting stuck on one programming language / technology that is not used in my country

Quoting Keynes in a lecture

Is there a way to get `mathscr' with lower case letters in pdfLaTeX?

Is there a RAID 0 Equivalent for RAM?

Recommended PCB layout understanding - ADM2572 datasheet

putting logo on same line but after title, latex

Picking the different solutions to the time independent Schrodinger eqaution

Keeping a ball lost forever



How to insert data in ascending order into an array in vba excel?


How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to convert a column number (eg. 127) into an excel column (eg. AA)CopyOrigin on Insert in Excel VBADifference between Visual Basic 6.0 and VBAIs there a way to crack the password on an Excel VBA Project?Excel to CSV with UTF8 encodingHow to avoid using Select in Excel VBAVBA Code to sort an Excel Column in Ascending Order and Expand Selection?Merge two lists in Excel in ascending or descending ordervba code to insert row and data in ascending order













-1















In excel vba, I have a range of random numbers between 1 and 10 and they are not in order. What is the shortest way to insert these random number in an ascending order into an array? Also names in order from A to Z?










share|improve this question



















  • 3





    What have you tried so far? Please share any code you have.

    – BigBen
    Mar 8 at 2:19











  • Wouldn't simply using the "Sort & Filter" button in xcel do the trick. Seems vba is over-kill here..

    – alowflyingpig
    Mar 8 at 2:30















-1















In excel vba, I have a range of random numbers between 1 and 10 and they are not in order. What is the shortest way to insert these random number in an ascending order into an array? Also names in order from A to Z?










share|improve this question



















  • 3





    What have you tried so far? Please share any code you have.

    – BigBen
    Mar 8 at 2:19











  • Wouldn't simply using the "Sort & Filter" button in xcel do the trick. Seems vba is over-kill here..

    – alowflyingpig
    Mar 8 at 2:30













-1












-1








-1








In excel vba, I have a range of random numbers between 1 and 10 and they are not in order. What is the shortest way to insert these random number in an ascending order into an array? Also names in order from A to Z?










share|improve this question
















In excel vba, I have a range of random numbers between 1 and 10 and they are not in order. What is the shortest way to insert these random number in an ascending order into an array? Also names in order from A to Z?







excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 8:14









Pᴇʜ

24.4k63052




24.4k63052










asked Mar 8 at 2:17









SasSas

1




1







  • 3





    What have you tried so far? Please share any code you have.

    – BigBen
    Mar 8 at 2:19











  • Wouldn't simply using the "Sort & Filter" button in xcel do the trick. Seems vba is over-kill here..

    – alowflyingpig
    Mar 8 at 2:30












  • 3





    What have you tried so far? Please share any code you have.

    – BigBen
    Mar 8 at 2:19











  • Wouldn't simply using the "Sort & Filter" button in xcel do the trick. Seems vba is over-kill here..

    – alowflyingpig
    Mar 8 at 2:30







3




3





What have you tried so far? Please share any code you have.

– BigBen
Mar 8 at 2:19





What have you tried so far? Please share any code you have.

– BigBen
Mar 8 at 2:19













Wouldn't simply using the "Sort & Filter" button in xcel do the trick. Seems vba is over-kill here..

– alowflyingpig
Mar 8 at 2:30





Wouldn't simply using the "Sort & Filter" button in xcel do the trick. Seems vba is over-kill here..

– alowflyingpig
Mar 8 at 2:30












1 Answer
1






active

oldest

votes


















1














Sas, if it has to be done in VBA, this would do the trick (tested):



Sub Arrays()

Dim ws As Worksheet
Dim MyRange As Range
Dim x As Integer
Dim arr_MyArray() As Integer

Set ws = Worksheets("Sheet1")
Set MyRange = ws.Range("A1", ws.Range("A10"))
ReDim arr_MyArray(1 To MyRange.Cells.Count)

For x = 1 To UBound(arr_MyArray)
arr_MyArray(x) = Application.WorksheetFunction.Rank(x, MyRange, 1)
Next

End Sub


Come check out ExcelVBADude YouTube Channel!






share|improve this answer


















  • 1





    That's a strange way to set a range. Why not ws.Range("A1:A10")

    – urdearboy
    Mar 8 at 3:51












  • Sorry, used to setting non-contiguous ranges. And, you can't spell strange without range! hehe

    – J VBA
    Mar 8 at 4:10











  • 1 point for making me realize that range("a1", "a10") actually works and is equivalent to range("a1:" & "a10"), and that it is actually faster to provide 2 strings rather than concatenate them (tried in a 10000 loop)

    – Patrick Honorez
    Mar 8 at 8:32










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055791%2fhow-to-insert-data-in-ascending-order-into-an-array-in-vba-excel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Sas, if it has to be done in VBA, this would do the trick (tested):



Sub Arrays()

Dim ws As Worksheet
Dim MyRange As Range
Dim x As Integer
Dim arr_MyArray() As Integer

Set ws = Worksheets("Sheet1")
Set MyRange = ws.Range("A1", ws.Range("A10"))
ReDim arr_MyArray(1 To MyRange.Cells.Count)

For x = 1 To UBound(arr_MyArray)
arr_MyArray(x) = Application.WorksheetFunction.Rank(x, MyRange, 1)
Next

End Sub


Come check out ExcelVBADude YouTube Channel!






share|improve this answer


















  • 1





    That's a strange way to set a range. Why not ws.Range("A1:A10")

    – urdearboy
    Mar 8 at 3:51












  • Sorry, used to setting non-contiguous ranges. And, you can't spell strange without range! hehe

    – J VBA
    Mar 8 at 4:10











  • 1 point for making me realize that range("a1", "a10") actually works and is equivalent to range("a1:" & "a10"), and that it is actually faster to provide 2 strings rather than concatenate them (tried in a 10000 loop)

    – Patrick Honorez
    Mar 8 at 8:32















1














Sas, if it has to be done in VBA, this would do the trick (tested):



Sub Arrays()

Dim ws As Worksheet
Dim MyRange As Range
Dim x As Integer
Dim arr_MyArray() As Integer

Set ws = Worksheets("Sheet1")
Set MyRange = ws.Range("A1", ws.Range("A10"))
ReDim arr_MyArray(1 To MyRange.Cells.Count)

For x = 1 To UBound(arr_MyArray)
arr_MyArray(x) = Application.WorksheetFunction.Rank(x, MyRange, 1)
Next

End Sub


Come check out ExcelVBADude YouTube Channel!






share|improve this answer


















  • 1





    That's a strange way to set a range. Why not ws.Range("A1:A10")

    – urdearboy
    Mar 8 at 3:51












  • Sorry, used to setting non-contiguous ranges. And, you can't spell strange without range! hehe

    – J VBA
    Mar 8 at 4:10











  • 1 point for making me realize that range("a1", "a10") actually works and is equivalent to range("a1:" & "a10"), and that it is actually faster to provide 2 strings rather than concatenate them (tried in a 10000 loop)

    – Patrick Honorez
    Mar 8 at 8:32













1












1








1







Sas, if it has to be done in VBA, this would do the trick (tested):



Sub Arrays()

Dim ws As Worksheet
Dim MyRange As Range
Dim x As Integer
Dim arr_MyArray() As Integer

Set ws = Worksheets("Sheet1")
Set MyRange = ws.Range("A1", ws.Range("A10"))
ReDim arr_MyArray(1 To MyRange.Cells.Count)

For x = 1 To UBound(arr_MyArray)
arr_MyArray(x) = Application.WorksheetFunction.Rank(x, MyRange, 1)
Next

End Sub


Come check out ExcelVBADude YouTube Channel!






share|improve this answer













Sas, if it has to be done in VBA, this would do the trick (tested):



Sub Arrays()

Dim ws As Worksheet
Dim MyRange As Range
Dim x As Integer
Dim arr_MyArray() As Integer

Set ws = Worksheets("Sheet1")
Set MyRange = ws.Range("A1", ws.Range("A10"))
ReDim arr_MyArray(1 To MyRange.Cells.Count)

For x = 1 To UBound(arr_MyArray)
arr_MyArray(x) = Application.WorksheetFunction.Rank(x, MyRange, 1)
Next

End Sub


Come check out ExcelVBADude YouTube Channel!







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 3:39









J VBAJ VBA

16715




16715







  • 1





    That's a strange way to set a range. Why not ws.Range("A1:A10")

    – urdearboy
    Mar 8 at 3:51












  • Sorry, used to setting non-contiguous ranges. And, you can't spell strange without range! hehe

    – J VBA
    Mar 8 at 4:10











  • 1 point for making me realize that range("a1", "a10") actually works and is equivalent to range("a1:" & "a10"), and that it is actually faster to provide 2 strings rather than concatenate them (tried in a 10000 loop)

    – Patrick Honorez
    Mar 8 at 8:32












  • 1





    That's a strange way to set a range. Why not ws.Range("A1:A10")

    – urdearboy
    Mar 8 at 3:51












  • Sorry, used to setting non-contiguous ranges. And, you can't spell strange without range! hehe

    – J VBA
    Mar 8 at 4:10











  • 1 point for making me realize that range("a1", "a10") actually works and is equivalent to range("a1:" & "a10"), and that it is actually faster to provide 2 strings rather than concatenate them (tried in a 10000 loop)

    – Patrick Honorez
    Mar 8 at 8:32







1




1





That's a strange way to set a range. Why not ws.Range("A1:A10")

– urdearboy
Mar 8 at 3:51






That's a strange way to set a range. Why not ws.Range("A1:A10")

– urdearboy
Mar 8 at 3:51














Sorry, used to setting non-contiguous ranges. And, you can't spell strange without range! hehe

– J VBA
Mar 8 at 4:10





Sorry, used to setting non-contiguous ranges. And, you can't spell strange without range! hehe

– J VBA
Mar 8 at 4:10













1 point for making me realize that range("a1", "a10") actually works and is equivalent to range("a1:" & "a10"), and that it is actually faster to provide 2 strings rather than concatenate them (tried in a 10000 loop)

– Patrick Honorez
Mar 8 at 8:32





1 point for making me realize that range("a1", "a10") actually works and is equivalent to range("a1:" & "a10"), and that it is actually faster to provide 2 strings rather than concatenate them (tried in a 10000 loop)

– Patrick Honorez
Mar 8 at 8:32



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055791%2fhow-to-insert-data-in-ascending-order-into-an-array-in-vba-excel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived