Sqaure Every Element In A Dynamic Array
Nov 11, 2009
I am trying to sqaure every element in a dynamic array and display the result . I donot understand how can I select the value in the cell using VBA?
Dim Y as variant, d() as double, i as long, j as long, rows as double, cols as double
Set Y = Application.InputBox("select the matrix: ", Type:=8)
Rows = UBound(Y)
Cols = UBound(Y, 2)
ReDim d(1 To Rows, 1 To Cols)
for i = cols
d(1,i) = ______==>
How do I select the value of element in that particular cell and how do I sqaure it?
I know
cells(rowindex, columnindex)
is used to select a particular cell but If I have a large array it would be difficult to go cell by cell and sqaure it.
View 9 Replies
ADVERTISEMENT
May 2, 2013
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.
View 9 Replies
View Related
Mar 22, 2007
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.............
View 7 Replies
View Related
Jun 22, 2007
how to get the table_array element of vlookup to either obtain details from a worksheet cell, or to enclose a variable (specifically part of the filepath) within the table_array formula. I have a template that gets saved and used in various directories, and I want Vlookup to to dynamically lookup information from a specific file that is also contained within the directory, without having to find and replace the directory name in the vlookup formulas.
View 2 Replies
View Related
Mar 19, 2014
I have 9 named ranges on worksheet Sheet1. I want to print every combination of every non-singular range on worksheet Sheet2. Below is a simplified version of the scenario.
There are three named ranges: Letters, Colors, Animals. Say the below are the entries for each range.
Letters = {A, B, C}
Colors = {Red, Blue}
Animals = {Dog}I want to print every combination of Letters and Colors but exclude Animals since it only has 1 entry.
Therefore my result would look something like this:
A Red
B Red
C Red
A Blue
B Blue
C Blue
My thought is to make a multidimensional array GrandArray where GrandArray(1) = Letters and GrandArray(2) = Colors, then recursively go back through every combination and print to Sheet 2. I can set up GrandArray, but stepping through each element is creating mismatch errors.
I'm trying to avoid For loops since my real data has 9 ranges which may or may not be included in the final print.
View 1 Replies
View Related
Jun 20, 2008
How can you test that no single element of an array is equal to a particular value?
View 9 Replies
View Related
Jul 28, 2006
I need to multiply matrix variable by a constant (each matrix entry has to be multiplied by the constant).
Sub Matrix()
Dim X As Variant, Y As Variant
Dim a As Integer
a = 2
X = [1, 1, 1; 2, 2, 2; 3, 3, 3]
Y = X * a ' Here it writes that type is mismached
End Sub
I read that in cell functions it is possible to do such calculations.
View 4 Replies
View Related
Oct 2, 2007
I am trying to pass information that is filled by user in a userform into an excel sheet. Let's say a user would click on a control button in a userform and Macro would ask him what value to store for the first variable. If user clicks one more time then Macro would identify that it was a second click and ask what value to set for a second variable. It is easy to do with limited number of variables, but is it possible that the variable which stores a number of clicks would become a number for variable to store the value?
1 click - a1 = ..
2 click - a2 = ..
....
n click - an = ..
If not possible - which way to search a solution?
View 5 Replies
View Related
Jul 7, 2006
I am trying to assign an array element to select a specific cell then assign a value to it. Below is the general code that I am working with. Does anyone know why this is not working?....
View 8 Replies
View Related
Apr 2, 2007
I am trying to count the number of items in an array, but want to protect against someone inserting a row and changing the position of the first item destined for the array. The first item is in F25.
TickerNum = Sheets("Dashboard").Range(Range("f25"), Range("f25").End(xlDown)).Count
Is there a way to ensure that it always picks up the value currently in f25.
View 9 Replies
View Related
May 16, 2014
Presently I calculate a worksheet and store the result in any array the size of which is determined at the start. I then enter all the results in a worksheet and get the max and min values and numerous other data. I am trying to find a way to get the max and min values without having to enter the data to speed the routine up.
this is the code that puts the results into a worksheet.
Code:
Sub Recalculate() 'Recalculates the WorkBook
Dim Calc_
Worksheets(startSht).Select
Set Output = Application.InputBox(prompt:="Please select the 1st Output Range.", Title:="SPECIFY RANGE", Type:=8)
Set OutPutLabel = Application.InputBox(prompt:="Please select Label for
[Code]....
View 1 Replies
View Related
Aug 10, 2006
I have a workbook that launches a form for a user to confirm (or un-confirm) some data retrieved from an Access database. I would like to put the "confirming" aspect of the process into a checkbox array. The recordset can return anywhere from 1 to around 12 records. I would like to add the checkboxes on the fly based on how many records were returned. Anyone have some sample code to show me how to add these to the form at run time?
View 9 Replies
View Related
Oct 1, 2013
I'm trying to create an index array that resizes its array starting location.
{=IFERROR(INDEX($V$17:$AU$17,1,MATCH(TRUE,V18:AU18
View 3 Replies
View Related
Mar 6, 2010
How can I make a dynamic array public?
I have to Dim it so it stays valid only inside the sub.
Public MyVar()
Sub test1()
Dim MyVar()
ReDim MyVar(1 To 4)
For x = 1 To 4
MyVar(x) = "ffffff"
Next x
End Sub
Sub test2()
For x = 1 To 4
Range("A" & x) = MyVar(x)
Next x
End Sub
Error I get is 'MyVar(x) = Subscript out of range'
View 9 Replies
View Related
May 9, 2007
I am trying to replicate the following code using Cells references so that the row can be made a variable. I basically want to make the search array smaller with each loop.
LMatch = WorksheetFunction.Match(Cells(3, 3), Sheets("Product Matrix").Range("B3:B250"), 0)
The above works, the following two variations don't:
LMatch = WorksheetFunction.Match(Cells(3, 3), Sheets("Product Matrix").Range(Cells(ArrayStart, 2), Cells(250,2), 0)
LMatch = WorksheetFunction.Match(Cells(3, 3), Sheets("Product Matrix").Range("B3:B250").Item(ArrayStart, 2), 0)
View 7 Replies
View Related
May 16, 2008
I play in a rock band and i'm trying to create a randomly generated set list based on categories.
Rock, Blues, Slow, & Original are the categories
My sheet of songs is sorted perfectly by these categories already and I have dynamic ranges already named to their respective categories.
the module i am using to randomize these categories does not dynamically expand....
View 8 Replies
View Related
Aug 10, 2012
Excel 2007 is my version. I'm trying to build an array from a dynamic range. I will know the column letter and lastrow.I think I could do this via a FOR and NEXT routine but there has to be a more efficient way. Here is my inefficient code idea:
Code:
Dim orgctarray(65000) As Variant 'because I don't know how long the array will need to be
Dim cnt as integer
Dim startrow as integer[code]....
So as you see, technically, I need to take sheet1.range("B3:B" & lastrow) and turn it into a vb array (I don't want to copy the data to some hidden worksheet and do the work there)I'd also like to remove duplicates and sort orgctarray alphabetically after I have completed building it.
View 5 Replies
View Related
Jun 28, 2007
(Auto)Filter or a listbox somehow functioning like it?
Hi Excel guru's, i've got the following question:
Can I fine-tune the AutoFilter function so it filters more flexible? ....
View 9 Replies
View Related
Jun 13, 2007
im currently using a static array to select multiple sheets at once which works alongside another Sub
Sheets(Array("Group1", "Group2", "Group3", "Group4")).Select
i have a button that creates a new sheet and names it "GroupX" X being the next number, it automatically adds on the right number by itself and it works fine...
i want it my array to be dynamic so that i dont have to manually edit the array and the macro every time i add a new sheet.
i have tried things like:
Dim MyArray As Variant
Dim Shts As String
K = Sheets.Count - 4
For p = 1 To K
Shts = "Group" + p
Redim MyArray(K) As String
MyArray(K) = Shts
Next p
Sheets(MyArray(K)).Select
View 9 Replies
View Related
Apr 15, 2008
the built in "Join" function can join all elements of a 1-dimensional array into a string with delimiter. Now, how do I do that with multi-dimensional array if I just want to join 1 dimension of it.
For instance, I have:
m = 10
n = 20
Redim my(m, n)
'assign values to array here...
'I want to join, say, my(5, 0 to n) only
'How to do that without declaring a new 1 dimension array?
Also, I want to write a join sub/function to do the above for n-dimensional array, do I need to write each one for every number of dimension (1 sub for 2-dimension, 1 sub for 3 dimension, etc.)?
View 4 Replies
View Related
Nov 20, 2008
I'm trying to create a dynamic array so that when a user enters the first sheet name via an input box, excel will know to select the other sheets with ending (2), (3), (4) etc.
Currently this code works only if there are 4 sheets present (as I set this way), anything lower/higher is out of range.
How do I make it so that it will select sheets if there are less than 4 sheets present?
I tried nesting, but I pretty sure this array needs redimming or something. Is ubound a better option?
View 5 Replies
View Related
Jun 22, 2012
I've am array formula that I use to provide highest values:
Code:
{=INDEX(Data!$D$2:$D$128, MIN(IF(LARGE(Data!$D$2:$D$128,ROW(A1))
=Data!$D$2:$D$128, ROW(Data!$D$2:$D$128)-MIN(ROW(Data!$D$2:$D$128))+1)),
MATCH(LARGE(Data!$D$2:$D$128,ROW(A1)), INDEX(Data!$D$2:$D$128,
MIN(IF(LARGE(Data!$D$2:$D$128,ROW(A1))=Data!$D$2:$D$128, ROW(Data!$D$2:$D$128)-
MIN(ROW(Data!$D$2:$D$128))+1)), , 1), 0), 1)}
I want to replace the range Data!$D$2:$D$128 with a dynamic reference: like that one:
Code:
ADDRESS(MATCH(Summary!$B$1,Data!$Q$2:$Q$10000,0)+1,
MATCH(Summary!$B$7,Data!1:1,0),1,1,"Data")&":"&ADDRESS(
MATCH(Summary!$B$1,Data!$Q$2:$Q$10000,0)+COUNTIF(Data!$Q$2:$Q$10000,Summary!$B$1),
MATCH(Summary!$B$7,Data!1:1,0),1,1,"Data")
The two formulas work well in separate sheets but crash when put together, how could I possibly insert the second address formula into the first one?
View 2 Replies
View Related
Feb 11, 2014
I have 7 sheets including the table as you can see on the attached. Now, each sheet is allocated to individual items e.g. item 10, item 20 and so on. I can't figure out how to return all the Item 10, 20, 30 ... to the corresponding sheet. It says Item 40 to all sheets.
View 8 Replies
View Related
Jul 20, 2009
I found quite a few posts about this problem, but none of the answers was any use to me. I need to redimension a 2 dimensional array in a Sub. I deleted all the code that is not of interest:
View 3 Replies
View Related
Jan 24, 2010
I'm trying to do, I already have a macro that takes certain cells in sheets in a workbook and copies to them to individual workbooks that are open.
So for example, I have a workbook with sheets A, B, and C.
and then I have a macro that'll copy sheet A to an open workbook D and B to an open workbook E, and so on.
Problems I'm running into = if the workbook isn't open, it crashes, I'd like to have an if then statement where if workbook is not open, it stops?
Additionally, I'd like a for statement because there will be 10 or more sheets in total, so would be nice to have a for statement that changes the variables so For i = 1 to 10 where 1 would be D and 2 would be E and so on so it automatically changes the workbook names as necessary.
View 10 Replies
View Related
Dec 19, 2008
For example, I have 2 columns:
john------2
rick-------1
andrew---3
john------5
I want on the third and fourth column the result like this:
john------7
rick-------1
andrew---3
I want to count automatically the number of elements taken by john, rick and andrew.
View 7 Replies
View Related
Jul 4, 2012
I have such a table:
A
01-Jun-12
B
02-Jun-12
C
02-Jun-12
[Code] ......
As you can see the letters repeat, and the dates are in order. Dates may repeat or be skipped.
I want to know how I retrieve the last date in the list that corresponds to a certain letter. For example, the last date that corresponds to "A" is 10-Jun-12. Similarly for "B", it is 11-Jun-12.
VLOOKUP will retrieve the first day.
In this case corresponding to "A":
=VLOOKUP("A",A2:B12,2,FALSE)
Is there any way I can retrieve the last day with a formula?
View 9 Replies
View Related
Dec 11, 2007
My main report (Report 1) has part number, serial number, and work order information, among other things I need. Report 2 contains this information as well, but also has a work order item number, which is needed in Report 1. Otherwise, Report 2 has nothing else of interest.
What functions will allow me to get the item number information I want from Report 2 into Report 1?
I have spent a lot of time trying various combinations of VLOOKUP, SUMPRODUCT, IF, etc with no luck. There is probably a very simple (I hope!) thing that I am overlooking.
View 9 Replies
View Related
Apr 20, 2014
I have the need to create a workbook that will return values based on the entering of an abbreviation. I will use the chemical elements as an example, I wish to have a column formatted so that if 'Au' is entered the cell populates with 'Gold' or if 'Pb' is entered then the cell is populated with 'Lead'
So in my case I have all the abbreviations in one column and all the full descriptions in another (approx 500 different codes/description)
View 3 Replies
View Related
Feb 11, 2014
I am trying to parse a section of html into excel but I don't know how to parse into a new row with each pattern rotation. I can do this both in Word and notepad++, but I can't find the same function of replace-with-line-break in excel's find-and-replace box.
Original html extract:
"shb":{"landline":"£1","mobile":"£1","text":"8p","mms":"24p"},"af":{"landline":"18p","mobile":"18p","text":"8p","mms":"24p"},"ak":{"landline":"3p","mobile":"3p","text":"8p","mms":"24p"},"al":{"landline":"10p","mobile":"25p","text":"8p","mms":"24p"},"dz":{"landline":"5p","mobile":"27p","text":"8p","mms":"24p"},
Results I need:
Capture.PNG
There is only one line as such in the entire page, so I don't need to loop through "blocks" of html codes with multiple lines.
I have had a look around and not sure what would be a good way to tackle this. RegEx (how to do it in excel macro)? HTML tags parsing (but these are not strictly tags)? I need to extract the correct section from page source as well, but I imagine this shouldn't be too hard. The url to the page I am extracting from is [URL] ........
View 3 Replies
View Related