How to extract rows in Excel with a given name by function 'xlsread' in Matlab? - excel

I have 100 Excel sheets of financial statement to extract selected data. For instance, the first sheet is from company A, its 'Total assets' item is in A10, but in the second sheet the 'Total assets' is in A17, the third in A12....
So every financial statement's items have different positions in their Excel sheet. Is there any way I can extract them by specify their name, such as 'Total assets', 'Other earning assets' etc, then I don't need to read their location one by one.

sorry about the delay. You'll want to import the data using
[num,txt] = xlsread('EXCELFILEHERE');
num will be a matrix of the numerical values while txt is a cell array of all the text values. Next you'll need to search txt for your desired phrase using something like
[row,col] = find(ismember(txt,'Total Assets')==1)
This will give you a list of columns and the corresponding rows where you'll find that phrase in txt. Then it's just a matter of plugging that row back into num to get the data you need. Keep in mind that the sizes of num and txt might be a bit off depending on how your data is formatted. I suggest .xls files if you can.

Related

Excel check if cell contains text from list and return values from list for every match

I have a list of products with Material no and Text description as visible in Sheet1 image.
Every part of the text has a defined value in another sheet.
How to get result in Sheet1 column C for each product based on its Text description and appropriate values defined in Sheet2?
Let's say I would like to parse the text and for each part of text to determine the value from another sheet and summarize this to one number.
For example:
Material 1 has A B C D in Text, formula should result with 100 => 10+20+30+40 (A=10+B=20+C=30+D=40)
etc...
I know I can use IF to check for each variant then return value with vlookup, but this is something I would like to avoid. Variants will change, their number can be pretty big therefore I would like to avoid changing formulas every time when we change Variants...
Looking by your screenshots you have a version of Excel prior to Micrososft365. In that case I think you can use:
Formula in C2:
=SUMPRODUCT(ISNUMBER(FIND(" "&E$2:E$11&" "," "&B2&" "))*F$2:F$11)

Index and Match with mulitple sheets and parameters

At work we have a large collection of sheet that I'm trying to add a couple columns to.
Some of the Index functions were already in the sheets so I am trying to base my new index function off of it because I have never used these types of functions in Excel. The old function is as follows.
=INDEX('Order Detail'!$D:$D,MATCH($A9,'Order Detail'!$B:$B,0))
Order detail is the name of the sheet that is holding the date for the output.
A9 is the part number in the current sheet.
And the part numbers are listed in column B or the order detail sheet.
What I know want to do is match the part numbers for the two sheets and match the dept number. The dept number is located in column L of the order detail sheet and I want that to match 1000-1. Not 1000 minus 1 actual 1000-1.
IF both of those match I want to spit out the data from column O in the order detail sheet and output that in column U starting at U9 and down in the current sheet.
This is what I have so far for this but it does not work.
=INDEX('Job Routing'!$O:$O,MATCH($A9,'Job Routing'!$B:$B,0),MATCH('Job Routing'!$L:$L,"1000-1"),0)
I only want it to output the O column if the Part Number AND Dept Number are the same as the part number in A9 and the dept number the same as 1000-1.
Any ideas?
Thanks

Fill out a column based on 2 other colums

I am trying to build a macro that will allow me to automatically fill out the cells in a column based on 2 criteria, which are the county and the project type, both of which are their own column names. The column to be filled out will be called "Frequency Band", which will have a static range of 12 possible values.
For example, if the County is "Bergen" and the Project Type is "2", then the Frequency Band will be "800Mhz". If it is the same county (Bergen) but the project type is "3", then the frequency band will be "1900MHz".
I currently have the list of Frequency Bands listed in another worksheet (Just call it sheet 2, cells E2 – E13), so I imagine that the outline of the VBA code would look something like:
If County(A) = Lee AND Project Type(B) = 2 Then Frequency Band(C) = 800Mhz(E3)
Else if Project Type = 3 Then Frequency Band = 1900MHz
Etc., Etc. for each county
Since I’ve never coded in VBA before and have no idea of its syntax, I don't really know where to begin with a formula like this. Could anyone help get me started?
Here is one way it would work with a formula.
In cells G1:K6 there is a table with your stored data (could also be on another sheet)
Column A you put in a country, column B you put in a project type (would be good if you validated against your source data.
Column C is your lookup function
'=INDEX($H$2:$K$6,MATCH(A2,$G$2:$G$6,0),MATCH(B2,$H$1:$K$1,0))
Index takes 3 main inputs:
the array (H2:K6) which is the actual frequency values
a row number in this array, and a column number in the array
For the row number lookup your country in the list you have (g2:g6) and it will tell you it is the x number in the array which corresponds to the row in the index array
Same thing with the column and project type.
There is a ton of information on the net about index and match if you need more information.
Highlighing is to show which values the formula has picked in my three examples below.

Excel: If Cell in Column = text value of X, then display text (in the same row, but different column) on another sheet

This is a confusing request.
I have an excel tab with a lot of data, for now I'll focus on 3 points of that data.
Team
Quarter
Task Name
In one tab I have a long list of this data displaying all the tasks for all the teams and what Quarter they will be on.
I WANT to load another tab, and take that data (from the original tab) and insert it into a non-list format. So I would have Quarters 1,2,3,4 as columns going across the screen, and Team Groups going down. I want each "task" that is labeled as Q1 to know to list in the Q1 section of that Teams "Block"
So something like this: "If Column A=TeamA,AND Quarter=Q1, then insert Task Name ... here."
Basically, if the formula = true, I want to print a list of those items within that team section of the excel document.
I'd like to be able to add/move things around at the data level, and have things automatically shift in the Display tab. I honestly have no idea where to start.
If there is never a possibility that there could be more that 1 task for a given team and quarter, then you can use a formula solution.
Given a data setup like this (in a sheet named 'Sheet1'):
And expected results like this (in a different sheet):
The formula in cell B2 and copied over and down is:
=IFERROR(INDEX(Sheet1!$C$2:$C$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$B$2:$B$7=B$1),),0)),"")
I came across this situation. When I have to insert the values into a table from an Excel sheet I need all information in 1 Column instead of 2 multiple rows. In Excel my Data looks like:
ProductID----OrderID
9353510---- 1212259
9650934---- 1381676
9572474---- 1381677
9632365---- 1374217
9353182---- 1212260
9353182---- 1219361
9353182---- 1212815
9353513---- 1130308
9353320---- 1130288
9360957---- 1187479
9353077---- 1104558
9353077---- 1130926
9353124---- 1300853
I wanted single row for each product in shape of
(ProductID,'OrdersIDn1,OrderIDn2,.....')
For quick solution I fix it with a third column ColumnC to number the Sale of Product
=IF(A2<>A1,1,IF(A2=A1,C1+1,1))
and fourth Column D as a placeholder to concatenate with previous row value of same product:
=IF(A2=A1,D1+","&TEXT(B2,"########"),TEXT(B2,"########"))
Then Column E is the final column I required to hide/blank out duplicate row values and keep only the correct one:
=IF(A2<>A3,"("&A2&",'"&D2&"'),","")
Final Output required is only from Column E
ProductID Order Id Sno PlaceHolder Required Column
9353510 1212259 1 1212259 (9353510,'1212259'),
9650934 1381676 1 1381676 (9650934,'1381676'),
9572474 1381677 1 1381677 (9572474,'1381677'),
9632365 1374217 1 1374217 (9632365,'1374217'),
9353182 1212260 1 1212260
9353182 1219361 2 1212260,1219361
9353182 1212815 3 1212260,1219361,1212815 (9353182,'1212260,1219361,1212815'),
9353513 1130308 1 1130308 (9353513,'1130308'),
9353320 1130288 1 1130288 (9353320,'1130288'),
9360957 1187479 1 1187479 (9360957,'1187479'),
9353077 1104558 1 1104558
9353077 1130926 2 1104558,1130926 (9353077,'1104558,1130926')
You will notice that final values are only with the Maximum Number of ProductSno which I need to avoid duplication ..
In Your case Product could be Team and Order could be Quarter and Output could be
(Team,Q1,Q2,....),
Based on my understanding of your summary above, you want to put non-numerical data into a grid of teams and quarters.
The offset worksheet function will work well for this in conjunction with the match or vlookup functions. I have often done this task by doing the following steps.
In my data table, I have to concatenate the Team and quarter columns so I have a unique lookup value at the leftmost column of your table (Note: you can eventually hide this for ease of reading).
Note: You will want to name the input range for best formula management. Ideally use an Excel Table (2007 or greater) or create a dynamically named range with the offset and CountA functions working together (http://tinyurl.com/yfhfsal)
First, VLOOKUP arguments are VLOOKUP(Lookup_Value,Table_Array,Col_Index_num,[Range Lookup]) See http://tinyurl.com/22t64x7
In the first cell of your output area you would have a VLOOKUP formula that would look like this
=Vlookup(TeamName&Quarter,Input_List,Column#_Where_Tasks_Are,False)
The Lookup value should be referencing cells where you have the team names and quarter names listed down the sides and across the top. The input list is from the sheet you have the data stored. The number three represents the column number the tasks are listed in your source data, and the False tells the function it will only use an exact match in your putput.

Random excel function with no duplicates and unfixed data

I need to translate an old program working on AS/400 that was picking random students to work for my city. I can use any program, as long as it works. To make it simple and fast, i chose excel.
However, i come over a small problem. I need to have no duplicates, because the same student can't do 2 jobs over one summer. Also, i need this to be flexible, since every year, new students will be added and some will be deleted.
This function works almost as much as i would want it:
=INDEX($A:$A,RANDBETWEEN(1,COUNTA($A:$A)),1)
The index $A:$A gets all the lines in the column A. So even if i add 20 names, it will take them into consideration. Then it choose randomly a value (the name) between the line 1 and the number of total lines (COUNTA) in the column $A. The problem with this method is that it allows duplicates.
Another function i found was to create a colum full of =ALEA() and then rank these by the numbers. This is not very pretty, but at least, there is no duplicates. The problem comes from my formula, that is static, and that i can't make flexible:
=INDEX($A$2:$A$74,RANK(B2,$B$2:$B$74))
My names are in the colum $A and my random values in colum $B. What i say is, rank the value in B2 (then B3, then B4, etc.) that is found in the column B.
What i would like is to integrate the COUNTA into the second function and (IF POSSIBLE) take the RANDBETWEEN instead of the rank function so that i don't have ugly numbers.
I am opened to use the first function with some kind of duplicate check. As long as the secretary doesn't have to do a lot of manipulation, it should be fine.
Thanks a lot for your help xox
I've created something in VBA that does what I think you want. Now keep in mind I'm very new with VBA, so it probably isn't the prettiest thing. To be clear, I had 10 names in column A from rows 1 to 10 and then simply ran this subroutine and it generated a list of unique names in column F. Here's my code:
Sub getRandom()
Do While Application.WorksheetFunction.CountA(Range("A:A")) > 0
Dim count As Integer
count = Application.WorksheetFunction.CountA(Range("A:A"))
Dim name As String
name = Application.WorksheetFunction.Index(Range("A:A"), Application.WorksheetFunction.RandBetween(1, count))
Dim row As Integer
row = Application.WorksheetFunction.Match(name, Range("A:A"), 0)
Range("F11").Select
Selection = name
Rows(row).EntireRow.Delete
Loop
End Sub
If you wanted to get the names one at a time, just remove the loop. How it works is it does exactly what you did with the INDEX and RANDBETWEEN functions, grabs the name in column A with that generated number, then deletes that row entirely, and thus no unique name is generated.
I chose column F arbitrarily and cell F11 specifically since that cell will not be affected when the rows are deleted.
I hope this helps, and if it's not what you were looking for I'll see if I can enhance it a bit.
There are many examples available for doing this in VBA (google Excel Random Unique) One of the best is from CPearson.Com which includes (among others):
Random Elements From A Range Of Worksheet Cells
You can also create a function that returns a number of elements in random order and without duplicates from a range of worksheet cells. The function below does just this. You can call as an array formula with a formula like
=RandsFromRange(A1:A10,5)
where A1:A10 is the list of elements from which to pull the values and 5 is the number of values to return. Enter the formula in a range with as many cells as you specify to return, and press CTRL SHIFT ENTER rather than just ENTER.
If you don't want to use VBA then then it can be done with a few simple steps:
Insert a column next to your student names, with the formula =RAND()
Sort the list of names and random numbers on the number
Pick as many students as you want fromm the top of the list
Each time you sort you get a new random ordering

Resources