Home > Software engineering >  EXCEL VBA array under boundary always fixed value how change automatically
EXCEL VBA array under boundary always fixed value how change automatically

Time:09-19

Question: array UBound (arr) -- 'not after this value to get a value according to the actual change, how to deal with, how to upload attachment?
Convenient please contact QQ1104859173

Private Sub CommandButton21_Click ()
Dim arr, arrtemp
Dim I %, j %, % 's array with variable
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' table 3 c summary data
Sheets (" table 3 c "). The Activate
Arr=Sheets (table 3 "c"). The Range (" A1: L & amp;" [c3000]. End (xlUp). Row)
MsgBox UBound (arr) 'this value will not change according to the actual, according to 1543, actual it is 1422
ReDim arrtemp (1 To UBound (arr), 1 To 12)
S=0
For I=8 To UBound (arr) 'data area start from line 8'
If IsNumeric (arr (I, 5))=True And arr (I, 5) & gt; And 0 Then 'number as a numeric value & gt; 0 rows selected
S=s + 1
For j=2 To 12 'as the original table number not To choose A
Arrtemp (s, j)=arr (I, j)
Arrtemp (s, 1)=s' this as a new serial number
Next
End the If
's a valid data rows
Next
Sheets (" table 3 c "). The Range (" a1675 "). The Resize (s)=arrtemp from array paste value
''* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Sheets (" table 3 b "). The Activate
Arr=Sheets (table 3 b "). The Range (" A1: L & amp;" [c3000]. End (xlUp). Row)
MsgBox UBound (arr) 'this value will not change according to the actual, according to 1683, actual it is 1543

ReDim arrtemp (1 To UBound (arr), 1 To 12)
S=0
For I=8 To UBound (arr) 'data area start from line 8'
If IsNumeric (arr (I, 5))=True And arr (I, 5) & gt; And 0 Then 'number as a numeric value & gt; 0 rows selected
S=s + 1
For j=2 To 12 'as the original table number not To choose A
Arrtemp (s, j)=arr (I, j)
Arrtemp (s, 1)=s' this as a new serial number
Next
End the If
's a valid data rows
Next
Sheets (table 3 b "). The Range (" a1516 "). The Resize (s)=arrtemp from array paste value
'
End Sub

CodePudding user response:

UBound () is to obtain an array subscript "high value",
With the size of the array (if it is a dynamic array, depending on the actual situation of a call), the subscript of the "lower bound value (initial subscript),"
Which dimension "and" (if it is a multidimensional arrays), what are you doing to modify it!!!!!!


You really want to "change", just with Redim to specify the array size,
If it is "fixed array", related parameters can be modified by array descriptor to change (dynamic array can change it, of course),
Just, really necessary to have this operation???????

CodePudding user response:


UBound function



Returns a Long data type, the dimension of the available maximum value of the specified array subscript,

Syntax

UBound (arrayname [, dimension])

UBound function grammar contains the following parts:

Part of the description
Arrayname required, the name of the array variable, follow standard variable naming conventions,
Dimension optional; Variant (Long), specify which returns the upper bound of the dimension, said the first 1 d, 2 said the second dimension and so on, if you omit dimension, is considered to be 1,


Description

UBound function used with the LBound function, used to determine the size of an array, LBound used to determine the upper bound of the one dimensional array,

For an array with the following dimensions, UBound return values to see the table below:

Dim A (1 To 100, 0 To 3, 3 To 4)

Statements return value
UBound (A, 1) 100
UBound (A, 2) 3
UBound (A, 3) 4
  •  Tags:  
  • VBA
  • Related