Dump Contents Of Multidimensional Array To Worksheet
Jan 23, 2009Rather 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 RepliesRather 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 RepliesI'd like to "dump" an array onto a worksheet. It's called MyArray, it's varying in length, 7 "columns" wide, and I know the uppermost left cell I'd like to dump to.
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]......
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: ...
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
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.
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
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.
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.
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
How can I lock the contents of an array so that they won't disappear when using auto-filter. "Freeze Panel" doesn't seem to do the job properly.
View 9 Replies View RelatedI have stored the contents of a worksheet table to an array, thus:
Code:
Public TeamArray() As Variant
Sub StoreTeamsToArray()
Dim NoOfTeams, NoOfColumns As Integer
[Code]....
The first column of the array contains team names, the second represents a colour that will be used for the background of a cell, the third represents the colour that will be used for the font of a cell.
What I now want to do is cycle through the first column of the array to see if the value contained within it matches the value contained in another variable ("Team"), then store the corresponding values from the second and third columns to other variable names ("BackgroundColour" and "FontColour".
I have a spreadsheet that lists accounts and I need to sum those accounts from data another worksheet. The problem is that the cell sometimes will have multiple accounts.
So a vlookup or sumproduct will not bring back the results when that happens.
For example
A2 = 626
no problem sumproduct or vlookup will work
A2 = 626, 627, 628, 629
problem can't lookup the 4 different accounts to pull the answer.
How can I make a formula see the value in column as an array to pull the answers?
I've created a textbox, call it Textbox1, where I've set EnterKeyBehavior and WordWrap to be true. If someone types something like
apples
bananas
cherries
in the textbox, and I use the following code
Code:
Dim TextBoxVal as String
TextBoxVal = Textbox1.Value
then TextBoxVal will be applesbananascherries.
I'd like to have the array be something like
apples,bananas,cherries, or
applesX_X_XbananasX_X_Xcherries,
or something else so I can tell when the user has hit the enter key. Is there any way to do this?
OK, two files attached in the zipfile, pricelist-half.xls and pricelist-full.xls
The background is that i exported a file from our warehouse system so we could update prices and re-import it. That is the pricelist-half.xls
After our staff had spent a few days working on it, it came to light that (as the name suggests!) its only about half the products that should have been exported that are on the list.
Hence the second file, pricelist-full.xls which as its name suggests is the full
product list.
What I need to happen, to make this as painless as possible, is somehow for the items/rows that are on the full list, but not on the half list to be inserted to the half list but also have a yellow background for their rows so they stand out clearly.
I have a cell that contains parts that are comma separated. I want to assign each of these parts to an element in an array so I can process them using a loop function.
Example Cell A1 = t4567, g8905, z3030
partArray = (t4567, g8905, z3030)
Is there a method or function i can use to achieve this?
I am trying to place the contents of an array into a column on the sheet. I can enter the array into 1 cell (which strings the values), but I can't seem to make range(1)=array(1).
View 9 Replies View RelatedI'm attempting to clear the contents from a range of cells on rows where a cell string may equal R, X, XX, Y, Z, ZX, #N/A.
The macro runs fine until it gets to a cell that contains #N/A. How to get this to work?
Sub Recalculate()
Dim r As Integer
r = ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For Row = 13 To r
[Code] ........
I am getting a DUMP on the "ActiveWorkbook.SaveAs Filename:=ThisFile" which is a valid PATH. Is there a Charachter max length required in A1?
ThisFile = "S:AccountingSales" & Range("A1").Value
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub
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.
I've been given the task of automating a spreadsheet to assess whether work has been done by each employee. Every employee has their own spreadsheet, where column A is a job code, and column H contains either y or n dentoting whether they have completed the task (y) or not (n).
The main spreadsheet is designed to show any outstadning tasks across everybody so it has a list of everybodies names in column A and then any incomplete tasks will be listed from columns b onwards next to the appropriate person. Here is what I have done at the moment.
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
Any way to look up any cells with in a data dump (example: PR1420829-V2) but not having to include the 'V2' but still picking up the cell.
Im currently using the fomula;
=IF(ISNA(LOOKUP($D$5:$D$1000,Test!$C:$C,Test!$L$1:$L$381)),"",LOOKUP($D$5:$D$1000,Test!$C:$C,Test!$L$1:$L$381))
I have a model which I have created a macro for that will do a data dump of the date when I hit 'update' (on BBG Raw Data Tab) to Column A in the 'Data for Pivot' Tab.
This works fine and all of the data comes over, except the last two data points in BBG Raw data (Cell A5055 and A5056) do not come across into the 'Data for Pivot' Tab (these should be going into Cell A5054 and A5055 of the 'Data for Pivot' tab).
I have a daily data dump that starts at the beginning of 2012 up to the current date. I have an executive view that allows the user to see metrics(in a data graph) from the current date back to a date selected from a drop down menu. I would like to have it so they can choose what the end date will be as well as the start date. I have tired using offset with very little luck. Is there a way I can accomplish this task with VBA? Everyday a new row of data (for the previous date) is added to the front sheet. So row 1 is a header row and then row 2 is 01/01/2012, row three 01/02/2013, etc.
View 7 Replies View RelatedI am trying to find a way to automatically do a query and dump the data into a sheet when a previously created workbook is open. I know how to get the data (use the Tools, Import External Data option to retrieve data from Access) but what I don't know is how to make it do it automatically when the workbook is open.
View 2 Replies View RelatedI 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)
I have a worksheet that has 2 columns on it 1 is numbers and the others are
names. I want to be able to export a group of names from one of my programs
and then have excel match the name and dump the corresponding number into the
spreadsheet. I beleive I can use vlookup but I am not certain
I have an organizational hierarchy dump in excel from an SAP ERP system. The format of that file is less than user friendly and I need to convert it to a flat file format so I can do pivots against it or possibly dump it into access database. The background is as follows (I am also attaching a file).
The organizational structure is multinoded/layered. Top most node is a company second from the top are divisions designated by 02DivName each 02DivName has multiple nodes assigned to it. The lowest level of the hierarchy is a department, always a numeric, always same length.
That's where it gets interesting. Each node/layer under 02DivName has a technical description and text description they get broken up into two different columns when SAP dumps them. Technical descriptions can be used to identify where in hierarchy the node falls(parent/child). For example 02A is a child of 02DivName 02B is a child of 02A 02C is a child of 02B and of course all of them roll up to 02DivName. There could be multiple 02A's under Div Name and their respective 02B's, C's D's would roll under them. So on export file it would be graphically represented 02A1 blank blank blank blank in that column and then change to 02A2 their respective 02B's would be in different columns works the same for C's and D's.
Here is another wrinkle the department is not always assigned to the lowest level grouping. I could have 02DivName dept, dept, dept, and then 02A group assigned to 02DivName. The department numbers end up on export file in the same column as fre form text descriptions for the nodes. It is staggered format.
The object of what I'm trying to do is basically convert the gibberish described above into flat file format via a vba script. I need to have node1 node1 desc node2, node2 desc, etc etc in columns the last column being a department number. So if for example I have a dept assigned directly to 02DivName directly all the other node descriptions will be blank if it's node 02A then the node1 and node2 will be populated. Any help will be appreciated. And here is the file with excel spreadsheet
I have a sheet with a data dump containing data on several railcars, taking up approximately 500 rows. Some railcars take up multiple rows, one row for each unique customer, and one railcar can have up to 5 customers' goods on it. What I need to do is get this information separated out onto monthly sheets, based on the departure date of the railcar. Every row of data in the dump has a column with the departure month I need in it, so that would make it seem easy. I have 12 sheets created one for each month, with the same headers as in the dump.
The two tricky parts:
1. The data in the dump is not sorted by railcar number, but the results in the monthly sheets need to be.
2. I don't believe LOOKUPS will work because rows in the dump repeat railcar numbers because of the multiple customers, and each of those rows has to be brought over to the monthly sheets, sorted and subtotaled by railcar number.
Finally, every week or so, I'm going to want to drop a new data dump in the dump sheet and need the monthly sheets to update dynamically. The new dump won't simply be rows added on to the same data as before, all the rows could be different. If this is solved most easily with a macro (i.e. drop the new data in the dump sheet, press a macro button and it populates the monthly sheets)