Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is it possible to check the length of each item in a specific field in an
array? Is so, how? I am building an array but I want to check the length of a specific field for each item in the array. For example, each "record" in my array has 4 fields. I want to check the length of the first field in each "record". If it is greater than 0, I will do one action and if it is zero I will do another action. I'm using this in an edit to be verify the user has not selected a record where the first field is blank. Thanks for the help. -- JT |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
JT,
Sub JTArrayTest() Dim i As Integer Dim j As Integer Dim myArr(1 To 2, 1 To 4) As String Dim NotEmpty As String For i = LBound(myArr, 1) To UBound(myArr, 1) For j = LBound(myArr, 2) To UBound(myArr, 2) myArr(i, j) = "String " & i & " " & j Next j Next i myArr(1, 1) = "" For i = LBound(myArr, 1) To UBound(myArr, 1) For j = LBound(myArr, 2) To UBound(myArr, 2) If Len(myArr(i, j)) = 0 Then MsgBox "array element " & i & " " & j & " is length 0" Else NotEmpty = NotEmpty & vbLf & i & " " & j End If Next j Next i MsgBox "Not Empty we" & vbLf & NotEmpty End Sub HTH, Bernie MS Excel MVP "JT" wrote in message ... Is it possible to check the length of each item in a specific field in an array? Is so, how? I am building an array but I want to check the length of a specific field for each item in the array. For example, each "record" in my array has 4 fields. I want to check the length of the first field in each "record". If it is greater than 0, I will do one action and if it is zero I will do another action. I'm using this in an edit to be verify the user has not selected a record where the first field is blank. Thanks for the help. -- JT |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
See VBA help for UBound
UBound Function Returns a Long containing the largest available subscript for the indicated dimension of an array. Syntax UBound(arrayname[, dimension]) The UBound function syntax has these parts: Part Description arrayname Required. Name of the array variable; follows standard variable naming conventions. dimension Optional; Variant (Long). Whole number indicating which dimension's upper bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed. Remarks The UBound function is used with the LBound function to determine the size of an array. Use the LBound function to find the lower limit of an array dimension. UBound returns the following values for an array with these dimensions: Dim A(1 To 100, 0 To 3, -3 To 4) Statement Return Value UBound(A, 1) 100 UBound(A, 2) 3 UBound(A, 3) 4 "JT" wrote: Is it possible to check the length of each item in a specific field in an array? Is so, how? I am building an array but I want to check the length of a specific field for each item in the array. For example, each "record" in my array has 4 fields. I want to check the length of the first field in each "record". If it is greater than 0, I will do one action and if it is zero I will do another action. I'm using this in an edit to be verify the user has not selected a record where the first field is blank. Thanks for the help. -- JT |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Assuming your field delimiter is a comma and that your array is named Record
LenFirstField = Instr(Record(X), ",") - 1 where X is the loop counter (record number). If you need this to be more general, here is how to LenOfField_F = Len(Split(Record(X), ",")(F - 1)) where F is 1 for the first field, 2 for the second, etc. and X is as defined above. Rick Is it possible to check the length of each item in a specific field in an array? Is so, how? I am building an array but I want to check the length of a specific field for each item in the array. For example, each "record" in my array has 4 fields. I want to check the length of the first field in each "record". If it is greater than 0, I will do one action and if it is zero I will do another action. I'm using this in an edit to be verify the user has not selected a record where the first field is blank. Thanks for the help. -- JT |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Second item in list using array | Excel Worksheet Functions | |||
Getting a the position of a single item in an array | Excel Programming | |||
Fastest way to find item in an array. | Excel Programming | |||
Lookup Multiple Occurrence Of Item In Array | Excel Programming | |||
does an item belong to an array? | Excel Programming |