Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi I'm hoping that someone out there can help me. Currently I'm just
trying to find out if there is a simple way to count the number of elements in an array, I was really hoping there would be a myarray.count property, or a sizeof type function that would return the number of elements. But I can't seem to find any way of doing this in the joy of the VBA help documentation. What I'm trying to do is get a task id e.g. 1, or 1.1, or 10.1.2 and based upon what level I want to drill down to either analyse the task data or not. To do this I thought I'd stick the task id into an array, split it on the "." and then count how many elements are in the array to determine what level the task is at e.g 1 = top level etc Below is a sample of the tester code I've been attempting to run: Sub tester() Dim checker_1 As String Dim checker_2 As String Dim checker_3 As String Dim counter Dim name name = "checker_" Worksheets("Project Export").Activate checker_1 = ActiveSheet.Range("A3").Value checker_2 = ActiveSheet.Range("A4").Value checker_3 = ActiveSheet.Range("A13").Value counter = 1 While counter < 3 Dim raggle_array() raggle_array = Split(checker_name & counter, ".") counter = counter + 1 Loop End Sub I just really can't work out how to get the number of elements back, and I really think it should be simple solution that doesn't involve a loop, but if it does involve a loop then it does involve a loop. Apologies for sounding bitter. Any and all help would be much appreciated, I'm new to VBA and finding it very difficult to cope with how complex everything I seem to want to do becomes. Thanks Madeleine |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Show us some sample data and the expected results based on that data.
I think that we could you help you better then. Cheers, Jason Lepack madeleine wrote: Hi I'm hoping that someone out there can help me. Currently I'm just trying to find out if there is a simple way to count the number of elements in an array, I was really hoping there would be a myarray.count property, or a sizeof type function that would return the number of elements. But I can't seem to find any way of doing this in the joy of the VBA help documentation. What I'm trying to do is get a task id e.g. 1, or 1.1, or 10.1.2 and based upon what level I want to drill down to either analyse the task data or not. To do this I thought I'd stick the task id into an array, split it on the "." and then count how many elements are in the array to determine what level the task is at e.g 1 = top level etc Below is a sample of the tester code I've been attempting to run: Sub tester() Dim checker_1 As String Dim checker_2 As String Dim checker_3 As String Dim counter Dim name name = "checker_" Worksheets("Project Export").Activate checker_1 = ActiveSheet.Range("A3").Value checker_2 = ActiveSheet.Range("A4").Value checker_3 = ActiveSheet.Range("A13").Value counter = 1 While counter < 3 Dim raggle_array() raggle_array = Split(checker_name & counter, ".") counter = counter + 1 Loop End Sub I just really can't work out how to get the number of elements back, and I really think it should be simple solution that doesn't involve a loop, but if it does involve a loop then it does involve a loop. Apologies for sounding bitter. Any and all help would be much appreciated, I'm new to VBA and finding it very difficult to cope with how complex everything I seem to want to do becomes. Thanks Madeleine |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
UBound(array) - LBound(array) + 1
-- --- HTH Bob (change the xxxx to gmail if mailing direct) "madeleine" wrote in message ups.com... Hi I'm hoping that someone out there can help me. Currently I'm just trying to find out if there is a simple way to count the number of elements in an array, I was really hoping there would be a myarray.count property, or a sizeof type function that would return the number of elements. But I can't seem to find any way of doing this in the joy of the VBA help documentation. What I'm trying to do is get a task id e.g. 1, or 1.1, or 10.1.2 and based upon what level I want to drill down to either analyse the task data or not. To do this I thought I'd stick the task id into an array, split it on the "." and then count how many elements are in the array to determine what level the task is at e.g 1 = top level etc Below is a sample of the tester code I've been attempting to run: Sub tester() Dim checker_1 As String Dim checker_2 As String Dim checker_3 As String Dim counter Dim name name = "checker_" Worksheets("Project Export").Activate checker_1 = ActiveSheet.Range("A3").Value checker_2 = ActiveSheet.Range("A4").Value checker_3 = ActiveSheet.Range("A13").Value counter = 1 While counter < 3 Dim raggle_array() raggle_array = Split(checker_name & counter, ".") counter = counter + 1 Loop End Sub I just really can't work out how to get the number of elements back, and I really think it should be simple solution that doesn't involve a loop, but if it does involve a loop then it does involve a loop. Apologies for sounding bitter. Any and all help would be much appreciated, I'm new to VBA and finding it very difficult to cope with how complex everything I seem to want to do becomes. Thanks Madeleine |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
iArrayCount = UBound(MyArray) + 1 - LBound(MyArray)
- Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "madeleine" wrote in message ups.com... Hi I'm hoping that someone out there can help me. Currently I'm just trying to find out if there is a simple way to count the number of elements in an array, I was really hoping there would be a myarray.count property, or a sizeof type function that would return the number of elements. But I can't seem to find any way of doing this in the joy of the VBA help documentation. What I'm trying to do is get a task id e.g. 1, or 1.1, or 10.1.2 and based upon what level I want to drill down to either analyse the task data or not. To do this I thought I'd stick the task id into an array, split it on the "." and then count how many elements are in the array to determine what level the task is at e.g 1 = top level etc Below is a sample of the tester code I've been attempting to run: Sub tester() Dim checker_1 As String Dim checker_2 As String Dim checker_3 As String Dim counter Dim name name = "checker_" Worksheets("Project Export").Activate checker_1 = ActiveSheet.Range("A3").Value checker_2 = ActiveSheet.Range("A4").Value checker_3 = ActiveSheet.Range("A13").Value counter = 1 While counter < 3 Dim raggle_array() raggle_array = Split(checker_name & counter, ".") counter = counter + 1 Loop End Sub I just really can't work out how to get the number of elements back, and I really think it should be simple solution that doesn't involve a loop, but if it does involve a loop then it does involve a loop. Apologies for sounding bitter. Any and all help would be much appreciated, I'm new to VBA and finding it very difficult to cope with how complex everything I seem to want to do becomes. Thanks Madeleine |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks very much to all of you for your prompt responses and instant
help, Ubound did the trick just perfectly. Ah I may actually have a weekend. Thanks again Madeleine Jon Peltier wrote: iArrayCount = UBound(MyArray) + 1 - LBound(MyArray) - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "madeleine" wrote in message ups.com... Hi I'm hoping that someone out there can help me. Currently I'm just trying to find out if there is a simple way to count the number of elements in an array, I was really hoping there would be a myarray.count property, or a sizeof type function that would return the number of elements. But I can't seem to find any way of doing this in the joy of the VBA help documentation. What I'm trying to do is get a task id e.g. 1, or 1.1, or 10.1.2 and based upon what level I want to drill down to either analyse the task data or not. To do this I thought I'd stick the task id into an array, split it on the "." and then count how many elements are in the array to determine what level the task is at e.g 1 = top level etc Below is a sample of the tester code I've been attempting to run: Sub tester() Dim checker_1 As String Dim checker_2 As String Dim checker_3 As String Dim counter Dim name name = "checker_" Worksheets("Project Export").Activate checker_1 = ActiveSheet.Range("A3").Value checker_2 = ActiveSheet.Range("A4").Value checker_3 = ActiveSheet.Range("A13").Value counter = 1 While counter < 3 Dim raggle_array() raggle_array = Split(checker_name & counter, ".") counter = counter + 1 Loop End Sub I just really can't work out how to get the number of elements back, and I really think it should be simple solution that doesn't involve a loop, but if it does involve a loop then it does involve a loop. Apologies for sounding bitter. Any and all help would be much appreciated, I'm new to VBA and finding it very difficult to cope with how complex everything I seem to want to do becomes. Thanks Madeleine |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Reference Elements w/in an Array | Excel Discussion (Misc queries) | |||
Non-unique elements in an array | Excel Discussion (Misc queries) | |||
Shifting Array Elements | Excel Programming | |||
Refer to Elements in an array | Excel Programming | |||
Count elements in array | Excel Programming |