I am trying to create code that will help me achieve the correct format. All I want is to pull employee (EE) entire row and paste into a new sheet, and then second part (ER) value to match the same employee.
In other words, if employee pay pension contributions for 100 (Pen EE (Tal)) and employer pay for 200 (Pen ERS (Tal)) on behalf of the same employee. Then, the worksheet should look like Column A= Pers No, Column B=Employee Name, Column C= ID Number, Column D=PenPay, Column E=Pens EE(Tal) and Column F=Pens ER(Tal) and G= Total (Pen EE +Pen ER values), as exactly in example tab.
I hope this makes sense. I have tried several methods but no luck so far. Thank you all for your help.
From your problem description, I think I can decipher that you are using Excel.
I see three basic approaches to solving your problem:
The simplest approach is not to use VBA at all and instead use the workbook functions INDEX and MATCH. The latter returns the row or column where an exact match is found in the search range, which has to be one dimensional. (The exact match actually requires the search option 0.) The function INDEX returns the value at the given row and column in a range. Combining both, you get a more flexible verision of VLOOKUP and HLOOKUP, which you can use to find the values in the second table for a given employee. (MATCH returns an N/A error if no match is found.)
The second approach is to use the Excel object model in VBA. You can search a range for a value using the Find method of the range. This returns the cell where the match is found and Nothing in case there is no match. If the search result is not Nothing, you can use the EntireRow property to get the entire row and the Cells property to select cells in the row.
Finally, you can use the support of SQL for Excel via ADODB. For a description how to do this, you can look at this Microsoft page and this old question on SO. Provided you know how to write SQL queries, this should enable you to solve your problem via SQL.
Related
I'm sorry I'm new to Excel, so I'm asking questions that I could probably Google if I new enough terminology to come up with a good search phrase.
Here's a simplification of my problem:
Using this table, I need to get the UIDs (and then the corresponding names, but that's easy) of every active player on "Team A":
Therefore, my result table should look like this:
The problem is unique-ness.
It's easy to find the UID using the conditions 'column C cells must have "Team A"' and 'column D must be TRUE"'... I find good old Arthur's UID, the first on the list.
Then I drag whatever formula down to the rest of the column, I find... Arthur's UID again (I've used VLOOKUP, INDEX/MATCH and XLOOKUP among others). I can't figure out how to get a result and then ignore that result after I've populated a cell with it.
How do I do this?
note I'm using Office 365 (in case there are non-backward-compatible formulas)
Use FILTER:
=FILTER(A:B,(C:C="Team A")*(D:D=TRUE))
I'm trying to use VLOOKUP to match activities with product codes, but run into an issue since VLOOKUP always returns the first match. I did a mockup below to describe my issue. To the left, I have a table with activity names and product codes.
To the right, in column G, I want to, based on matching activity names in column F with activity names in column A, assign the activities product codes from column B.
When I use VLOOKUP, it only matches with the first activity name and give all the activities with the same name the same product codes. I need them to get different product codes even if they have the same name. I want my function to "take the next one" on the list, when the first one is taken.
Should I try to use another function to solve this? Is it impossible with VLOOKUP? My 'real' document has like 2000 rows, and the solutions I found on Youtube was not good to scale.
Thanks in advance. I'm new to here so if I should clarify my question in any way, feel free to tell me.
If the raw is around 2,000 rows, you can use a nested index match with helper columns.
Add a rank in column C with the formula =COUNTIF(A2:$A$2,A2)
Then apply the same ranking in your output part as well (Ensure Activity Name is sorted so that the formula works), Output rank formula =IF(J2=J1,I1+1,1)
Formula that lists out the Product Code {=INDEX($B$2:$B$3190,MATCH(I2,IF($A$2:$A$3190=J2,$C$2:$C$3190),0))}
This is an array formula, you get the curly brackets by hitting control+shift+Enter instead of just Enter upon keying in the formula
If you are using excel 365, you can use UNIQUE formula.
=UNIQUE(A2:B18)
In the sheet1 i have a table called working days of the countries as shown in the below image.
In the Sheet2 i have 10 columns in that based on the country and month by referring the this table i am trying to populate the values, When i tried doing by Vlookup the first row alone getting populated, but in the second row the header from F1:T1 is getting changed to F2:T2 so rest of the cells showing as #NA.
Anyone can you please give a solution for my issue. Here is the formula i have used.
=VLOOKUP(I1,Sheet1!F2:T7,MATCH(Sheet2!M1,Sheet1!F1:T1,0))
Thanks in Advance.
You are missing the symbol $ to lock the ranges, and the false condition to match exact values in the VLOOKUP.
It should be like:
=VLOOKUP(I1,Sheet1!$F$2:$T$7,MATCH(M1,Sheet1!$F$1:$T$1,0),0)
Or instead of VLOOKUP use HLOOKUP like:
=HLOOKUP(M1,Sheet1!$F$1:$T$7,MATCH(I1,Sheet1!$F$2:$F$7,0),0)
In general, combining the INDEX and MATCH functions is a superior option to VLOOKUP. For example, =INDEX(Sheet1!F:F,MATCH(Sheet2!M1,Sheet1!F1:T1,0)). This allows you to go left-to-right or right-to-left as well.
Snip for Index Match functions Using Vlookup won't work here because in the 2nd table you are repeating the country, unlike the first table. Use a combination of index match function, this is little trickier than the vlookup but it will fulfill your requirements.
Since I don't have the exact table you shared so I created a table on my end and sharing the snip here.
I'm having a very difficult time with transitioning my VLOOKUP statement from simply referencing sheets and ranges (which work like a charm), to instead using table and column names.
I'm trying to make the VLOOKUP a bit more robust as the sheet where it is pulling from will constantly be changing data, so column numbers will change frequently. Thus, I'd like to just reference a column by its name.
I have converted the source data sheet to a table.
I have named all columns appropriately and double checked spelling.
This VLOOKUP works great (currently):
=VLOOKUP(E6,'Costs'!$A$2:$AE$84,19,FALSE)
However, what I would like to do is make it look this:
=VLOOKUP(E6,tblCosts[Order Number],tblCosts[June 2017], FALSE)
I have been fiddling with also trying to use MATCH which is not working either:
=VLOOKUP(E31,tblCosts[Order Number],MATCH(F4,tblCosts[June 2017],FALSE),FALSE)
UPDATE
This formula now works but it is returning the order number...not the cost for the month.
=VLOOKUP(E31,(tblCosts[Order Number]),(tblCosts[June 2017]),FALSE)
Normally I would keep trying this myself...but I am feeling overwhelmed and have been trying for hours. Any advice would be great.
Thank you!!
This should work for you:
=VLOOKUP(E31,tblCosts[#All],COLUMN(tblCosts[Jun-17]),false)
The COLUMN(TblCosts[Jun-17]) returns the column number of the field you want.
The VLookup searches the first column of tblCosts[#All] - (all the data in the table) for the data (in E31) and returns the data in the column you want.
This formula will continue to work even if you add columns or rows to the data.
Make sure that any heading which looks like a date in your spreadsheet eg "Jun-17" is stored as Text and not as a Date, as it will not match the string "Jun-17" when you use VLookup.
=VLOOKUP(E37,tblCosts[#All],match("Jun-17", tblCosts[#Headers]),FALSE)
This match is looking for the column name in all column headers and will return the number of columns to the right of the first column rather than the column number in the sheet. This avoids having to use COLUMN(tblCosts[Jun-17]) - COLUMN(tblCosts[Order Number]) + 1 when your table doesn't start in column A.
Ref: https://www.excel-university.com/vlookup-hack-4-column-labels/
Here are some statistics about my question(related to excel 2007)....
some thousands lines of data from web (so highly unstructured)....
Each row acting as a tuple ..(each row has data related to a particular entity with various attributes)
there are about 60-100 attributes for each row... i.e. some row has 60 attributes(followed by corresponding attribute value in next cell of same row) while some has 100 attributes(values)
These attributes are not structured and not in any particular pattern..(i.e. in some row Attribute "Music" is at column "A" and its associated value is at column "B" but in other row ,Attribute "Music" is at column "AB" and its value is at "AC"....
So here is my question
Is there any tool/excel utility which can group all attributes of same name under a particular column and its associated value in the next column .[IMP: the row order must not be changed as these attributes are associated row wise with some primary key]
This is a very broad question but I can give some suggestions. I don't know of any tool/utility to do what you need. However here are three options that you could use to get the result you want.
Figure out how to import into a database based on attribute name/value. Not sure this is possible without structuring the data first (organize each attribute into its own column).
Use formulas HLOOKUP/VLOOKUP/INDEX/MATCH to organize each attribute into its own column. No VBA with this option but uses very complex formulas.
Use VBA to loop through the rows and organize each attribute into its own column. This might be the easiest to implement logically but that depends on your skills.
Usually we want to see what you've tried before we help. You can explore each of these ideas on your own then post additional questions for specific problems you encounter. Show us your own effort as much as you can. We like to help correct specific code problems rather than simply create your program for you.
EDIT
Here are the formulas for method 2: The data is in Sheet1 and the formulas are in Sheet2.
Here is the formula in Sheet2!A2; copy down as far as needed.
=Sheet1!A2
Here is the formula in Sheet2!B2; copy down and across as far as needed.
=IF(ISERROR(MATCH(B$1,Sheet1!$A2:$K2,0)),"",INDEX(Sheet1!$A2:$K2,1,MATCH(B$1,Sheet1!$A2:$K2,0)+1))
Best wishes.