How to calculate the size of an input variant using UBound? Sometimes I need to do the transpose but sometimes I don't. I tried ON ERROR GOTO but it doesn't work in this case. Can you tell me how I could do that?
Public Function Shock(A_E As Variant, Year As Variant) As Double
This is the first portion of my code. When it reaches x1, it dies... I put in a break... when I highlight that line, it displays: UBound(myArray1, 1) =
Public Function M_ADD(myArray1, myArray2)
Dim i As Integer, j As Integer Dim x1 As Long, x2 As Long Dim y1 As Long, y2 As Long
I have a named range that is 993 cells in length (columns). I verified this in the name manager. In my VBA code I am getting a range error when I try to access element number 903. 903 should be the last one with any data in it. I can't see a reason why this would generate an error since i have not exceeded my size of 993.
Is there a VBA function or property that I can use to determine the size of an array?
I'm trying to set a range variable ('IngFore') as equal to a number of rows long and a number of columns wide via 'Cells'. The range needs to be dynamic in that the total number of rows and columns will vary over time. Hence, I've defined 'lastdate' to determine the last row in the array, and 'lastcol' to determine the last column in the array. The starting point for the array is I12.
It would appear that I can't quite get the syntax right.
Code: Set IngFore = (Cells(12,9 to lastdate,9)),(Cells(12, 9 to 12, lastcol))
I've tinkered with it here and there, removing and adding brackets but I can't get it to work.
I am trying to develop some code to serve as an 'undo' for several macros that I have. They each take a selected range and perform some changes to that range. I have managed to make some code that will undo the last macro run but would like to make something that can go back several steps. To that end, I have started with the following code but am running into an issue when I need to use a variant array to hold multiple arrays of a custom defined data type:
VB: Type SaveRange Val As Variant Addr As String
[Code] .....
This declares some public variables I'll need, each as an array so that I can iterate through several steps of do/undo using the undoIndex. I then use them to save each range I am about to change by calling the following macro within my actual data-manipulating macros:
VB: Sub Save_RangeForUndo(rng As Range) Dim i As Integer Dim cell As Range
undoIndex = undoIndex + 1
[Code] .....
If you look at the last line here, this is my problem; I can't figure out how to properly use an array to hold each instance of OldSelection() for later referral. Just for completeness, here is my actual undo macro:
VB: Sub Undo_Operation() Dim i As Integer OldWorkbooks(undoIndex).Activate OldWorksheets(undoIndex).Activate
[Code] .....
I need to get this OldSlctVariant()() array to hold each instance of OldSelection() so that I can restore them for each consecutive undo. I'm not very familiar with the variant type and anything more than the basic use of arrays.
I want to load one with data from a worksheet query table that will vary in size each time it's executed. The length will vary, but the range is continuous, and five columns wide. I'd prefer a do while loop, looping until a blank cell is encountered. Can someone get me started with general syntax and setup of the array?
I am trying to figure out how to make a userform to display the contents of a 2-D array which has a variable number of rows. I want the userform to height of the userform to correspond with the number of rows of data to display.
I don't have much experience with userforms, but here's what I was thinking: VBA code which would find the # of rows of data and then adjust the height of the userform and the length of the lable (which the data would go in).
I was looking for a worksheet with vba to do FFT beyond the Excel internal 4096 limit. I wanted to try my hand at writing code to do it faster. The attached does just that.
Everything worked fine until I went beyond 32k samples. The next higher 2^n value for data size to feed the FFT is 65556. When I tried this quantity of samples I got Runtime Error (13) type mismatch when attempting to write the array back to the worksheet using the "transpose" method.If I remember correctly, 32k worked.
Is there some limit to the size of the array that can be transposed and placed into a range? If so, is there another way to do this?
I do not need to re-write the data, but I use this same method elsewhere to write the FFT output. It it fails writing the input data back, it will probably fail when writing the FFT results.
My question is about using UBound with an array of User-Defined Data Type. I don't know how to use UBound to find the total elements in the following arrays called MealItem()
I have set up a worksheet to demonstrate how arrays work--and find that I need to learn more about the topic myself! The code below reads data from Column A into an array, sorts it, and then writes the sorted data to Column B. In the example I have created there are 11 data values in Column A. When I break at the indicated line of code, I find that LBound(sourceData) = 1 and UBound(sourceData) = 11, as expected. However, at the indicated line of of code, when i = 1, the reference to sourceData(i) results in a subscript error.
Public Sub AddSortedColumn() Dim sourceData() As Variant sourceData = Range("A1:A" & Range("A65536").End(xlUp).Row) Dim swap As Boolean Dim i As Integer Dim save As Variant swap = True Do While swap swap = False For i = LBound(sourceData) To UBound(sourceData) - 1..................
in C a string is nothing more than an Array of characters ending with a null character.
in VBA this does not seem to be the case.I am trying to use the BlowFish code from David Midkiff for some encryption, however the code sometimes fails:
When encrypting a string a string of a specific length should be returned. however sometimes one of the characters of the encrypted string is a null character, and the returned encrypted string (with a embedded null character) is causing me problems. I want to check for the null character and if present redo the encryption. But how do I check for the presence of this null character in a unicode (double-byte) string?
Checking with Len(encrypted) gives the correct length (!) but trying to move each (unicode)character into an array fails when using the Mid() function past the null character in the string.
Now I can use
byteArray() = StrConv(unicodetext,vbFromUnicode)
to get the lower byte of each character into an array easily, but how do I do this for both bytes of the unicode characters?
Using an integer array does not work other than through
intArray(j) = CInt(AscW(Mid(Outp, j, 1)))
which fails on the nullstring in my encrypted text.
I have tried with variants but so far no luck. I thought if the string was entered into a variant then I could also address the variant as an array of bytes, but that does not seem to be accepted by VBA.
I am trying to populate many arrays with the same code using something like this. For this test, assume the following data in A1.
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
Code: Sub populate() Dim firstArr(5), secondArr(5), thirdArr(5), fourthArr(5), fifthArr(5) As Integer Dim r, c, num As Integer
[Code]....
The above code does not work of course and falls over. I am unsure whether I should try and concatenate with something like this eg "" & arrName(i) = Cells (r,c) or go down a different route.
I have a class module with several private variables, including one that is an array of a user-defined type. I am trying to set the values of a single element of this array with "Property Let ..." from a string array:
Say I have 3 columns of data: A1:C10 and I want to run a Match() function on them all together to see if I get a match any one those cells, say the value of have in X1.
Since, Match only allows a One-Column lookup array.. is there a way to "concatenate" or "append" the 3 columns together within a formula so now I would be looking to Match in an array that is 1 column * 30 rows?
Basically want to convert =Match(X1,A1:C10,0) to =Match(X1,A1:A30,0) without moving around the raw data in the sheet.
And I want to avoid doing an AND or OR formula that uses 3 separate MATCH() for each column.
I have a hunch that the MMULT or MMULT/TRANSPOSE functions are involved, but can't seem to get it right.
I'm only starting to get to grips with arrays. I have what I consider to be a lot of data that I need to 'cut' into separate workbooks. I have written some code that does this by simply looping through each line, 250k+, checking against a variable and copying the row into a separate sheet. This took longer than it would have doing it manually. It was suggested to me that I use arrays to speed up the process. I have managed to store the test data into an array but am struggling to find a way to loop through and pull out an entire 'row' from the array based on a variable. I have looked for 2 days in various places to find some way to loop through the data held in the array, but to no avail.
That code will appear here from about 8am GMT tomorrow. I know that once I've cracked this I'm on the road to some very significant time saving and comprehensive report writing.
I then copy and paste 'values' and filter out the 'false' to get my final result.
This has worked in the past, but for some reason that I simply can't figure out, the formula isnt working! I've attached the example, and I've highlighted a number in blue (cell E522 and C103), (that should be being found in the 'LOOKUP' function) but is returning a "FALSE". I have looked over the code and simply can't figure out why Excel isn't returning the right value.
This is obviously happening for a quite a few of my numbers, as my filter result is returning an array that is about 1500 shorter than it should be. I have highlighted E522 as the 'example cell' to look at.
I've tried to multiply each element in a 6x6 array by a similar 6x6 array, both on the same sheet, and it worked.(see Macro2 and attached xls file "Test").Then I got more ambitious and tried to do the multiplication from a standard array in sheet "TestA", with the result on the same sheet, by each array in sheet "TestB" and failed.How do I solve this problem? Pgualb PS:I'm using the R1C1 style.
Sub Macro2() For y = 29 To 34 For x = 2 To 7 Cells(x, y) = Cells(x, y - 27) * Cells(x, y - 18) Next x Next y End Sub Sub Teste12() 'Multiplica matriz em TestB por matriz padrão em TestA com _ 'resultado na matriz em TestA correspondente à matriz em TestB ' Dim x, y As Integer For y = 2 To 7.............
Code: Sub testarray() Dim arr1 As Variant Dim rng1 As Range Dim lngX As Long
Set rng1 = [A2:A6] ReDim arr1(1 To rng1.Count, 1 To 2) For lngX = 1 To rng1.Count arr1(lngX, 1) = rng1.Cells(lngX, 1) arr1(lngX, 2) = rng1.Cells(lngX, 2) Next End Sub
Now, what I need to do, is create an array for each freq of all the items that share that freq. Essentially I need this:
0.5 {1,2,3} 0.25 {4,5} 0.125 {6}
Now, I was thinking, if I could create a dictionary object and make the key the freq (so my keys would be 0.5,0.25,0.125) then I could assing the "item" an array (or another dictionary) holding the items that apply to that freq.
i need to replicate what i did using array formulas with VBA macro (array variable). to make things clear and simple i created an example for illustration only. look at it & u will find what i did & what i need to do ,much of it in writing so that i accurately describe my problem. attached is my example
On one sheet (KPI) I have either the values "x" or "" in the range A84:A89 to mark wheter to use the corresponding project in the range B84:B89. On the sheet X-ref I have the same project names in range T4:Y4 and a corresponding target value in T8:Y8
What I want is the sum (or average) of the marked-projects target-values. The result should end up in KPI!G31. In other words I want
=sumif(A84:A89;"x";'X-ref'!T4:Y4)
but it doesn't work since the first range is an column-array and the second range is an row-array.