Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My array of strings is already sorted from A to Z:
mySort(1) = "apples" mySort(2) = "apricot" mySort(3) = "banana" mySort(4) = "beans" mySort(5) = "bread" mySort(6) = "donuts" '... etc, etc.. mySort(38) = "zuchini" Is there an easy function that can copy any alphabetical segment of the array into a new array? For example, if I give the function input "B", it should create this new array: myarray = Array("banana", "beans", "bread") Thanks! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Tatsujin" wrote in message
My array of strings is already sorted from A to Z: mySort(1) = "apples" mySort(2) = "apricot" mySort(3) = "banana" mySort(4) = "beans" mySort(5) = "bread" mySort(6) = "donuts" '... etc, etc.. mySort(38) = "zuchini" Is there an easy function that can copy any alphabetical segment of the array into a new array? For example, if I give the function input "B", it should create this new array: myarray = Array("banana", "beans", "bread") Dim i as Long, k as Long Dim myarray () As String ' code ReDim myarray (1 To 3) ' or 0 to 2 For i = 3 To 5 k = k + 1 myarray (k) = mySort(i) Next There are other efficient ways to copy entire or part arrays but complicated with string arays. The worksheet Index function would do it but not efficient and much faster to loop as above. Peter T |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Peter T" wrote in message
Seeing Claus' reply I realise I misread your question. Peter T |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Am Fri, 5 Feb 2021 14:43:22 -0800 (PST) schrieb Tatsujin: My array of strings is already sorted from A to Z: mySort(1) = "apples" mySort(2) = "apricot" mySort(3) = "banana" mySort(4) = "beans" mySort(5) = "bread" mySort(6) = "donuts" '... etc, etc.. mySort(38) = "zuchini" Is there an easy function that can copy any alphabetical segment of the array into a new array? if you don't know where your searched character starts in the array you can search the words beginnig with your expected character with Reg.Exp: Set re = CreateObject("vbscript.regexp") myString = Join(mySort, ", ") 'modify the first character as expected ptrn = "b.[a-z]{1,}" re.Pattern = ptrn re.Global = True re.ignoreCase = True Set matches = re.Execute(myString) For Each match In matches ReDim Preserve myArray(n) myArray(n) = match n = n + 1 Next Regards Claus B. -- Windows10 Microsoft 365 for business |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to extract data from an array | Excel Programming | |||
Extract multiple values from array | Excel Discussion (Misc queries) | |||
Extract a column/row from a 2-D array | Excel Programming | |||
How do I extract a single value from the linest array result? | Excel Worksheet Functions | |||
How do I extract hyperlink as text from an array of hyperlinks? | Excel Worksheet Functions |