Dictionary Object And Multidimensional Array
Dec 31, 2008
I have data in a dictionary object and need to load it into a two column listbox. The VBA help says you can load data into a multicolumn listbox from a 2D array. So my question is how can I extract the data from a dictionary object directly into a 2D array.
The dictionary object stores data in key and item pairs. So the 2D array would have one dimension for the keys and the other for the items. I want to do this without having to extract the items and keys into separate 1D arrays and then loop through them to build the 2D array.
View 9 Replies
ADVERTISEMENT
Mar 30, 2012
What I'm trying to do:
1) I have data that has a header row of 6-10 values (created, action, type, id, ...). The rows are unique records.
Click here to see the data
2) I originally wanted to read the data into one array (DataArray) and the header into another array (KeyArray). Then I would add additional unique information about each record (additional columns of info) into the DataArray.
3) I stumbled upon Dictionaries as a way of storing key/item pairs, which I thought could apply to each record since the headers are all unique and would be a way of storing key/items without needing to:
a) Know the ordering (if I used arrays I had to know the upper bound of the array to insert a column
b) Look up which what position in the array mapped to which column header
c) Resize the array every time I wanted to insert a new column of information on all the records
4) So now that I know about a dictionary object, I believe I need to create one Dictionary object for EACH record (row) of my data and then store those Dictionary objects within a one dimensional array such that each element of the array is a Dictionary.
5) This way I can iterate through each element of the array to access the dictionary inside and perform calculations on each record, depending on which key/item I needed to work with at a later point
Questions for Dictionary experts:
1) Is my approach sound?
2) What is the syntax for putting the dictionary of one row's worth of data into an element of a one-dimensional array?
View 8 Replies
View Related
Oct 31, 2009
I know the Dictionary Object is confined to the Microsoft Word Object structure though can it be used in Excel. If not, is there a suitable replacement.
View 3 Replies
View Related
Feb 27, 2013
I want to create a multidimensional array. Basically, I want to tie a file to a sheet. I want to import the following files:
"byemployee.csv",
"byposition.csv",
"Status report.xls",
"bydepartment.csv",
"byband.csv"
to the following sheets in my workbook:
"byEmployee",
"byPosition",
"statusReport",
"byDepartment",
"byBand"
Basically, I would like to pass the array by reference. Basically, the code below imports the file into my workbook, but I since I have several files going into sheets in the workbook, I don't want to write the code 5 times. I figured the best way would be to create a multidimensional array and pass through my procedure below.
Code:
Sub import_Employee_Data()
strSourceFile = ThisWorkbook.Name
strPath = ThisWorkbook.Path & ""
strFirstImportFile = strPath & "byemployee.csv"
sDestSheet = "byEmployee"
If Len(Dir(strFirstImportFile)) > 0 Then
[code]......
View 8 Replies
View Related
Feb 28, 2007
I’m working on a project where a spreadsheet holds data which is spread over multiple rows. The number of rows can change depending on the case.
Imagine 1 case being 1 row of certain details, then a various number of rows below detailing some different information in different columns.
A crude example is this: ...
View 9 Replies
View Related
Mar 9, 2007
I'm getting a compile error "Can't Assign to array" when I try to return a multidimensional array from a function. I'm not a VB expert, and I was unable to find any examples of returning a multidimensional array from a function. Here is some sample
Sub someSub
Dim data(1 To 4, 0 To 23) As Integer
For counter = 1 To numSheets
data = processData(counter, data) ' The error happens here
Next
End Sub
Private Function processData(counter As Integer, data() As Integer) As Integer()
Dim dataCopy(1 To 4, 0 To 23) As Integer
dataCopy = data
'modify dataCopy
processData = dataCopy
End Function
View 6 Replies
View Related
Jun 27, 2012
I am using a dictionary object from the MS Scripting Runtime library to store a series of arrays and perform operations on the array cells as necessary. There is a for loop to go through the process of creating all of these entries. My issue is that when using the .exists property, it is returning a True even before the item has been added. Closer debugging indicates that the key is being added to the dictionary at the beginning of the for loop, even though no .add command is used and will not be used until the end of the loop. The result is that the values in the arrays do not totalize as intended.
Code for the dictionary build has been included below. I have attached the Excel file which contains the appropriate module which calls that function
VB:
Option Explicit[ATTACH]46705[/ATTACH]
Function DictAppTable(Loop_Range As Integer, Key_Range As Range, Dim_1 As Range, Dim_2 As Range)
Dim DictTable As Dictionary
Dim AppElement(0 To 0, 0 To 1) As Variant
Dim iD As Integer
Dim strAppID As String
[Code].... the previous post, as the pared down excel file which I posted had a slight error which prevented it from running
View 2 Replies
View Related
Dec 5, 2013
I already did this with excel formulas and it works pretty good. The problem is that when I work with lots (tons) of data, it takes minutes for the formulas to update and do all the needed calculations.
I have been trying to solve this problem using a dictionary object, since it should work faster. However; I don't even know how to start.
My problem (see uploaded Workbook) is this:
I need to calculate daily profits from different departments. For that I need to subtract daily expenses from daily revenues. Unfortunately, the order of appearance of the departments is random. At the end it should look something like this for every day and department:
[Profit].[Dep?] = [TotalRevenue].[Dep?] - [TotalExpenses].[Dep?]
I really don't know what to do with...
Dictionary Object supports below methods :
Add - add key-item in dictionary object
Exists - Check the existence of key in a dictionary object
Items - Get the collection of all items.
Keys - Get the collection of all keys.
Remove - remove particular key-item
RemoveAll - Remove all keys-items
Dictionary Object supports Properties
Count - gets the count of keys
Item - sets or gets the item
Key - sets the key in dictionary object
View 9 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
Jul 15, 2014
I'm trying to pass a multidimensional array to a function that I have defined, but I receive an error about an object mismatch. Here is what I have in regards to the array and function. What should I change?
Code:
Dim diffArray() As Integer
Dim countArray() As Integer
Redim countArray(count,2)
diffArray = getRunningSum(countArray)
End Sub
Public Function getRunningSum(ByRef countArray() As Integer) As Integer()
'Code here......
End Function
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
Jan 23, 2009
Rather than looping through a multidimensional array to populate a worksheet, is there a quick function which can export the entire array to a worksheet?
View 2 Replies
View Related
Jul 18, 2014
How to apply a filter over the array "a" shown below and get the result in a new array "b" containing the filtered values based on the following conditions (the conditions criteria could be 1, 2 or 3. In this case only 2):
Criteria1 in Column 4="yellow"
Criteria2 in Column 3="ggg"
And only show values of columns 1 and 3.
If were using an SQL query would be something like this:
Code:
SELECT F[1],F[3] FROM "Table" WHERE F[4]="yellow" and F[3]="ggg"
The output array would be as below:
Code:
b=[{12,"ggg";140,ggg}]
this is the array:
Code:
Sub test()
a = [{"122","53","ggg","yellow";"140","9","ggg","yellow";"16","-22","ddc","yellow";"127","-37","ddc","green";"53","-28","ggg","grey"}]
'Filter code to get array b
'
'
End Sub
View 1 Replies
View Related
Apr 20, 2012
I would like to get data onto my worksheet that looks something like what I have below. I'm pretty set on using Dictionaries to get the data into this format
(row 1 reads): header 1, header 2, header 3
(row 2 reads): value 1, value 2, value 3
(row 3 reads): value 1, value 2, {"property1": property1, "property2": property2, "property3": property3}
I'm close to doing so but having issues with my syntax.
I can refer to:
arrExport(1)("key3") to get the value in key3
but I cannot refer to:
arrExport(1)("key4")
Because key4 is what contains another dictionary.
Code:
Sub DictWithinDict()
Dim dict As dictionary, dictValue As dictionary
Dim arrExport() As dictionary
Dim i As Integer
ReDim arrExport(1 To 10) 'real data will be in thousands
[Code] .....
View 3 Replies
View Related
Jan 10, 2014
I have two dictionary objects populated with various keys and items - Dict1 and Dict 2. I've read that the items of a dictionary object can be quite varied, even another dictionary! I know how to add items to keys if those items are strings say, but how to add an entire dictionary (Dict2) as the items of another dictionary (Dict1)?
View 5 Replies
View Related
Aug 12, 2013
Im trying to add hyperlinks to cells using an array but im getting "run time error 424 - object required" error. THe code im using is:
Code:
Sub hyper3()
' not WORKING - ARRAY to add hyperlink to cells
Dim rngIn As Range
[Code]....
View 3 Replies
View Related
May 11, 2009
how to tackle a piece of work that I really don't want to do.
We have extracted some summary information on one of our products. The workbook has 10 sheets, one for each of our 10 main sales channels. Each sheet has the same layout of information on. There are 7 tables on each sheet, and each one cuts the data in a different way (eg one summarises by age of purchaser (in age bands), another by demographic group etc). Each table then has the same 14 columns of key data (eg number of sales, average order value).
I've been asked to analyse this information "for anything interesting". At the moment, the only way I can think to do this is to print out the 10 sheets, sit down with a highlighter, and try to visually identify trends and anomalies. The idea fills me with dread, and I suspect will be quite inefficient.
I've asked whether I can get the data in a pivot table or some other format that might be more conducive to analysis, and have been told no. (There will easily be more than 100,000 lines in the original data (we're using Excel 2003)). To be honest, I'm not sure that I'd really be that much better off, even if it were in a pivot table.
View 9 Replies
View Related
Feb 14, 2009
if someone have a code for filter o limit a Listbox but with 6 columns and 6 textbox because i have a code but is only onedimensional works fine but i dont have any clue how to modify to works like multidimensional
this the one dimensional
Private Sub tbxFind_Change()
Dim vList As Variant
'Read the original list
vList = Range("A2", Cells(Rows.Count, 1).End(xlUp)).Value
'Convert it to a 1D array
vList = Application.Transpose(vList)
'Filter it
vList = Filter(SourceArray:=vList, _
Match:=tbxFind.Value, _
Include:=True, _
Compare:=vbTextCompare)
'Send it to the listbox
lbxCustomers.List = vList
End Sub
Private Sub UserForm_Initialize()
'Read the original list
lbxCustomers.List = Range("A2", Cells(Rows.Count, 1).End(xlUp)).Value
End Sub
View 9 Replies
View Related
Oct 11, 2006
I have written a user type for my arrays but I am having trouble storing it. The number of arrays varies.
Dim arrTransactions() As Transaction
Dim assortedrowindex As Integer
For assortedrowindex = 2 To 100
Redim Preserve arrTransactions(0)
arrTransactions(0).CUSIP = Cells(assortedrowindex, 12)
arrTransactions(0).OrderDate = Cells(assortedrowindex, 9)
arrTransactions(0).BuyCurncy = Cells(assortedrownindex, 2)
arrTransactions(0).SelCuurncy = Cells(assortedrowindex, 10)
arrTransactions(0).Fund = Cells(assortedrowindex, 7)
arrTransactions(0).SettleDate = Cells(assortedrowindex, 10)
arrTransactions(0).BuyUnits = Cells(assortedtrowindex, 15)
arrTransactions(0).FxRate = Cells(assortedrowindex, 16)
View 3 Replies
View Related
Aug 13, 2014
I have 2 dictionaries; both have a "location" and the "frequency of occurence". The 2nd dictionary locations are related to the first, but are named differently, so I have a range of cells I'm using to define the equivalent locations, ie:
Dict. 2 Location----Dict. 1 Location
Wrapper------------Packaging
Robot----------------Robot Arm
Robot----------------Robot Base
etc..
(It's not a direct 1 for 1)
The program is meant to take both dictionaries, convert the 2nd dictionary keys to the equivalent dictionary 1 keys (based on the cell range data provided) and then combine the values associated with that location and store them in D_Master. D_Master is a copy of my dictionary 1, in which I am also trying to add the values from dictionary 2.
I started by writing the location definitions within the program, i.e.:
[Code]....
which works, but there are several hundred definitions and it becomes less robust, whereas a user could type in a definition within the range of cells and the code below could take care of the rest.
View 5 Replies
View Related
Oct 31, 2009
i have to reverse a very big wordlist containing four coulmns. Column A words, Column B Transcription, Column C Grammar and Column D Meanings. Now i would like to make the meanigs (seperator is ";") to words and words to meaning in another new worksheet added by a macro. For example English-French would then become French-English wordlist.
If the original worksheets name is "x" then a new worksheet should be added with name "Re-x". This new sheet should then contain the new wordlist. For example:
View 12 Replies
View Related
Feb 23, 2010
When we should use scripting dictionary?
Any website recommendation on the net with a good explanation about this, related to use it in excel?
View 9 Replies
View Related
Sep 7, 2006
The comparison between 2 sheets is made in a Class and the Result of the comparison is to be coded in a Module. How the result has to look like is attached as result.xls
I think it has to beginn like this
Sub DisplayResult(ByVal RESULT As Dictionary)
.
.
.
.
End Sub
View 3 Replies
View Related
Nov 9, 2012
I have data in three columns A, B and C. In column A I have values like:
A
1. AOL
2. BA
3. HDP
and now if cell A1 has value AOL then in cell B1 only possible values are:
DD or DP or MP or MR or RE or TP or TT
if cell B1 has value DP then in cell C1 only possible values are:
KO or MA or RS or SA or SE or UM
if cell B1 has value MR then in cell C1 only possible values are:
KO or MA or RS or SA
View 6 Replies
View Related
Jul 29, 2014
I wish to make a transposition using dictionary. I wanted to take a script jindon, but I have difficulties to adapt.
VB:
Option Explicit
Sub test()
Dim a, i As Long, ii As Long, w, rng As Range, cpt As Byte
a = Cells(1).CurrentRegion.Value
[Code] .....
View 9 Replies
View Related
Jul 9, 2014
I have dictionary defined as series of keys and let's say two values:
name1,val1A,val1B
name2,val2A,val2B
...and so on
I would like to define named range from "name" column allowing user to select desired name from combo on another sheet. This is easy
But after that I would like to get val1 and val2 for selected name and show them with some calculation; For example to construct two columns like this: <nameX_selected_from_combo>, (<val1X>+<val2X>)/2
All the problem is how to select values from the same row as name selected in range.
View 2 Replies
View Related
Dec 23, 2007
I have two wordlists (dictionaries) in two sheets and want to make third dictionary out of them in a third sheet.
The first dictionary is Iranian-German and the second one is German-English. Now the macro is supposed to make a third dictionary Iranian-German-English. The new wordlist should contain all words from first list, even if some of them are not translated through macro.
attached excel file to understand the problem better.
Excel file
View 14 Replies
View Related
Nov 12, 2012
In my code below I have verified that the key that I am passing to the item is valid with a debug statement however the item is not being returned.
These two lines are not returning anything. The idea is to pass in the key and get the value.
Code:
Debug.Print dict.Item(Products.Cells(Target.Row, Target.Column - 4))
Products.Cells(Target.Row, Target.Column + 1).Value = dict.Item(Products.Cells(Target.Row, Target.Column - 4))
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Ingredients As Worksheet
Dim Products As Worksheet
Set Ingredients = Sheets("Ingredients")
Set Products = Sheets("Products")
' Culculate total cost
[Code] .........
View 1 Replies
View Related
Aug 25, 2008
given a key can i get the position within the dictionary that key/item was found?
so if i go
dic.add "skratch", "more"
dic.add "records", "dude"
how would i obtain the position of "records" within dic? is it possible ?
View 9 Replies
View Related
Jul 13, 2013
I have a VBA code which checks the value of two cells in "Sheet2", and when these values are in the fourth column of "Sheet4", then dictionary is saved and after that VBA delete Entire Rows in "Sheet4" which consists these values.
Please find the code below:
VB:
Sub dictionary1()
Application.ScreenUpdating = False
Dim dico1 As Scripting.Dictionary
Set dico1 = New Dictionary
[Code] .....
Now I wonder how to add more conditions like for example: "Delete all rows in "Sheet4" which have for instance in the 6th column text "Hello" AND which have in the 7th column value greater than 10". How can I change the existing code?
This is of course just an example, but the underlying question is how can I add to these dictionaries more conditions. Of course, we can still use "Sheet2" to add some value which we want dictionary to store.
I want to use for this only dictionaries because spreadsheet is large and filtering doesn't work at all...
View 7 Replies
View Related