Import data from nth columns to another sheet - excel

I'm trying to import all data from nth columns, starting from the 3rd row, from one worksheet ('Dataimport') to another ('Cleaned Data') in the same spreadsheet, but so far I have only managed to get a specific cell from every nth column:
=INDEX(Dataimport!$C$3:$HI$3;(ROWS($A$1:A1)*6)+1)
Right now I'm doing it manually, using =TRANSPOSE(IMPORTRANGE("1yyb1k0uAdN1XcLWBhNq4jA0eInnePRoUt9IbuXDmfEU";"Dataimport!I3:I300")) in every cell, so that the column data is imported horizontally (this is how it's supposed to look like):
The sheet with data looks like this. Here I want to retrieve data from every 7th column starting from column C:
Any idea how I do this?
Public link:
https://docs.google.com/spreadsheets/d/1hXFiSoduVjcZ6fbOcyp-BfI7m4So-01umLS0kBm-lVI/edit?usp=sharing

Proposed solution
Given your attempt =INDEX(Dataimport!$C$3:$HI$3;(ROWS($A$1:A1)*6)+1), I would suggest using the Google Sheets Formula OFFSET that allows specifying indexes as mathematical operations.
You will be able to specify the column offset with a simple mathematical operation in order to get the next needed indexes for the rows below.
Here is an example:
=TRANSPOSE(OFFSET(Dataimport!C$2:C$199;1;(ROW()-1)*6;199;1))
With this formula you can obtain the right column form the Dataimport Worksheet and then transpose it in order to fit it in a row.
Putting this formula in the Clean Data "D2" Cell will compute a column offset of 6 starting from the 3rd column ("C") considered in the OFFSET formula. Dragging down the formula will adjust the column offset index to the needed 7 columns range.
Reference
OFFSET

I think I have a solution.
I've build a spreadsheet with dummy data and then I made a formula that takes every nth column from the table.
Here is my solution:
https://docs.google.com/spreadsheets/d/1J6x4H_cNczRRo40Ri6Nwa-YnZOISpxZmG4-JZ7tA1kA/copy
First I make an ID column to both tables to let vlookup work
I use vlookup and arrayformula formula for this:
For grabbing multiple columns I use sequence formula within vlookup.
This makes an array of numbers with defined step. So if you can have every 6th column you define step as 6. Here step is defined in cell c23
=ArrayFormula(vlookup(A24:A43,A2:AB21,sequence(1,5,4,C23),false))
Of course it can work in multiple sheets or files. You just need to use importranges instead of standard references to a range.

Related

Data in column instead of rows

I am getting data from SQL Server into an Excel sheet. Its a customer table containing 20 records. The columns are Customer Code, Customer Name and Customer Short Name.
What I need is instead of data coming in rows (from row 2 to row 21)... it should come in columns.. i.e. 1st three rows of column A contains respective headers (code, name and short name) and column B first row contains value of code, second row value of name and third row value of short name... same continue to column C, D, E..... till all 20 records..
Is it possible in excel?
In Excel, you can easily transpose the array with your data. Consider the following sample data in the range A1:C4:
You could now select the entire range and copy it via CTRL+C -> Paste -> Transpose (T). A second possibility would be to enter the following formula in, e.g., cell E1: =TRANSPOSE(A1:C4). This is a dynamic array formula in the current version (Microsoft 365). If you have an older version, you have to enter the formula as a legacy array formula by confirming the formula with Ctrl+Shift+Enter.
The result is as follows:
Edit: Dynamic setting of range
Theoretically, assuming that the data structure remains the same in terms of the number of columns and rows, the formulaic approach will update the transposed array accordingly as the original data is updated. In the specification above, the range A1:C4 is hard coded. While it is very likely that the number of columns will remain the same (could also be dynamically adjusted), in practice additional rows could be added/deleted from the data. In this case, you can specify the number of rows dynamically, which solves this problem:
=TRANSPOSE(INDEX(A:C,1,1):INDEX(A:C,COUNTA(A:A),3))

If there is a repeated value in a column in excel, is there a way to have vlookup pass the first value and only use the second one?

I am using vlookup in excel to copy data from one column into another when a user enters a value.
The user enters a date in column Z, and vlookup searches for that value in column P, and copies over the corresponding x1,x2,y1,y2 values from columns Q,R,S,T into AA,AB,AC,AD.
As you can see in these pictures, the date 8/1 pops up twice, and vlookup uses the first date's coordinates, when I want it to use the second 8/1's coordinates.
Is there a way to bypass the first repeated value and use the second one instead?
There are many ways to do this.
The method below will return the LAST matching date.
For a formula solution, I chose to use Tables and Structured References:
AA2: =INDEX(Table1,LOOKUP(2,1/(Table1[[Date]:[Date]]=$Z2),ROW(Table1)-ROW(Table1[#Headers])),COLUMNS($A:A))
and fill right to AD
For a formula, without using the Table, you can use something like:
=INDEX(Sheet1!$P$2:$T$100,LOOKUP(2,1/(Sheet1!$P$2:$P$100=$Z2),ROW(Sheet1!$P$2:$T$100)-ROW(Sheet1!$P$1:$T$1)),COLUMNS($A:B))
The advantage of the Table is that your reference range will auto-expand as you add rows to the table, so you don't have to either oversize it, edit it, or use dynamic range references all of which have some issues.

How do I reference the last row in a named Excel table?

I am currently trying to format one column of my table so that if there are any names that match in another column, the cell in the original column will be highlighted. Here's an example of what I mean:
Row 10 has a prerequisite of the M6A1. However, row 11 has a name of M6A1. I would like the M6A1 in row 10 to be highlighted.
To do this, I figured I would use COUNTIF, with the range from the current row (10 in this case) down to the bottom row (14). I don't want to hard-code in 14 however, as the list length will change. Therefore, I thought that I could just call the last row in the table, but that's not a feature apparently. I would like to know either how to dynamically reference the last row in this table, or if there is a better way to do this.
If you consider using built-in Excel functions you can get the last row of the table or named range this way:
=ROW(NAMED_RANGE or TABLE_NAME)-1+ROWS(NAMED_RANGE or TABLE_NAME) - for the last row of the table;
=ROW(NAMED_RANGE or TABLE_NAME)-1+COUNT(NAMED_RANGE or TABLE_NAME) - for the last record in the table.
To get the last row of your table, use Range("A1").End(xlDown).Row, provided your "A" column does not have any blank cells. If it does, a better way to do it is to use Range("A1000000").End(xlUp).Row.
The .End(Direction) method goes to the last cell before a blank a cell in a given direction (Up, Down, Left or Right, preceded by xl), starting from the specified Range, and the .Row method gets the row number of a given Range/Cell.
I would suggest this code:
lastRow = ws.Range(affectedTable).Row + ws.Range(affectedTable).Rows.Count - 1
Expanding on a previous answer with what worked for me. Below is another solution that does not require VBA but will return the last populated row instead of the last row of the table area.
COUNT(TABLE_NAME) will return the total number of filled cells in the table. If there are blank cells, this may not work correctly.
Since we are trying to count rows, it makes more sense to use only one column of the table which will always be filled (in many cases the first column). Using the built-in COUNTA function, we can count only the cells that have a value. Use structured references to specify a single column in the table or named range:
=ROW(TABLE_NAME)-1+COUNTA(TABLE_NAME[COLUMN_NAME])
If you want that inside the table (totals cell for example), just use offset (no empty rows of course):
[code]=OFFSET(tblName[[#Totals],[ColName]],-1,0)[/code]
If it is out of table, there are many good solutions.

EXCEL: Searching a table of data with two criteria and outputting the rows to a new table

I have a table of data (Data!$A$8004:$F$10430) within an excel sheet which I need to search for all of the rows that contain the date displayed in cell: Data!Q27 (e.g may-2017) in column F of the table of data. And then output in a new table all of the rows which match that specific date (Data!Q27 changes, but is always in the MMM-YYYY format)
I created a similar solution for another table which worked, however for this data table it is not working. The working solution is shown below:
=IF(ISERROR(INDEX(Data!$A$1:$K$7523,SMALL(IF(RIGHT(Data!$A$1:$A$7523,7)=Data!$Q$25,ROW(Data!$A$1:$K$7523)),ROW(1:1)),1)),"",INDEX(Data!$A$1:$K$7523,SMALL(IF(RIGHT(Data!$A$1:$A$7523,7)=Data!$Q$25,ROW(Data!$A$1:$K$7523)),ROW(1:1)),1))
(This differs slightly as the date format in the table and Data!Q25 is /mmm/yy, but it successfully creates the new table which changes values dependent on the value in Data!Q25)
The format of the date in column F is e.g 09-May-2017 and is classified as 'general' type.
I have used this formula, and I get no error or value on the cell that this code is on:
{=IF(ISERROR(INDEX(Data!$A$8004:$F$10430,SMALL(IF(RIGHT(Data!$F$8004:$F$10430,8
)=Data!$Q$27,ROW(Data!$A$8004:$F$10430)),ROW(1:1)),1)),"",INDEX(Data!$A$8004:$F
$10430,SMALL(IF(RIGHT(Data!$F$8004:$F$10430,8)=Data!$Q$27,ROW(Data!$A$8004:$F$1
0430)),ROW(1:1)),1))}
The formula is formatted as an array, and therefore I believe this code should work, returning the first A column value of a row which fits the criteria of having, for example: "***May-2017" in its F column. However it doesn't.
Unfortunately due to corporate protection I am unable to share the spreadsheet, but if the information supplied in this isn't clear enough I could supply a new excel sheet to show my example?
https://drive.google.com/open?id=1NpS0_Bsy8XuicrPl8oy5tAswEa9QZ9X2 <- here is a spreadsheet that I have recreated to show the issue. The real spreadsheet is different, but this shows the purpose of my problem. Regardless of there being values which should be picked up on the tab names 'Data for normal user', no data is shown.
Thank you for your time!
Your formula is correct, however you haven't offset the rows.
Your INDEX() is starting at row 8 so this will be the first indexed row. SMALL() is building an array of the exact row numbers so row 8 in SMALL() is row 1 in the index, therefore no results are showing.
You simply need to update the IF() within SMALL() to handle this offset: (This formula has been updated to respond to formula dragging, i will include your original after)
=IFERROR(INDEX(ConfidentialLiveData!A$8:A$14,SMALL(IF(RIGHT(ConfidentialLiveData!$F$8:$F$14,8)=ConfidentialLiveData!$C$2,ROW(ConfidentialLiveData!$A$8:$A$14)-7),ROW(1:1))),"")
Or
=IF(ISERROR(INDEX(ConfidentialLiveData!$A$8:$J$14,SMALL(IF(RIGHT(ConfidentialLiveData!$F$8:$F$14,8)=ConfidentialLiveData!$C$2,ROW(ConfidentialLiveData!$A$8:$J$14)-7),ROW(1:1)),1)),"",INDEX(ConfidentialLiveData!$A$8:$J$14,SMALL(IF(RIGHT(ConfidentialLiveData!$F$8:$F$14,8)=ConfidentialLiveData!$C$2,ROW(ConfidentialLiveData!$A$8:$J$14)-7),ROW(1:1)),1))
A quick tip for error handling formulas is to use F9 when highlighting sections of your formula to show what that is calculating. For example i highlighted IF(RIGHT(ConfidentialLiveData!$F$8:$F$14,8)=ConfidentialLiveData!$C$2,ROW(ConfidentialLiveData!$A$8:$J$14)) and saw that that calculated as {8;FALSE;10;11;FALSE;FALSE;FALSE} so the match was being found just that the row numbers being returned were not what we were looking for.
Update:
So your formula is starting on row 8004, that row in the index is row 1. To get that row returned you need to take away 8003 from the 8109 to give you the 106th indexed row. A common way to do this is to take away the starting row and add 1 which in your original formula would be: {=IF(ISERROR(INDEX(Data!$A$8004:$F$10430,SMALL(IF(RIGHT(Data‌​!$F$8004:$F$10430,8 )=Data!$Q$27,ROW(Data!$A$8004:$F$10430)-ROW(Data!$A$8004)+1)‌​,ROW(1:1)),1)),"",IN‌​DEX(Data!$A$8004:$F $10430,SMALL(IF(RIGHT(Data!$F$8004:$F$10430,8)=Data!$Q$27,RO‌​W(Data!$A$8004:$F$1 0430)-ROW(Data!$A$8004)+1),ROW(1:1)),1))}

Generate a 3rd column sequential number based on two columns data

I apologize if the title is misleading, but
I have an issue where I need to generate a sequential number in a third column based on comparing data from two different columns.
My data looks like this:
Before
The entry with the 1 is the first point, I need to use the value in the 'Back' column to find the same value in the 'Front' Column, then add +1 to the point, so the result looks like:
After
Because of the naming conventions used, sorting either column by value will not work.
Appreciate the help!
Assuming you have the initial 1, and your number column is C, front is D, back is E, this would start at row 2:
=INDEX(C:C,MATCH(INDEX(D:D,MATCH(D2,E:E,0),1),D:D,0),1)+1
Image: http://i.imgur.com/0XfdLrk.png
Did you establish whether your data has duplicates or incomplete sequences?
Here's another formula which should achieve what you want and also doesn't rely on you knowing where the sequence starts. Every sequence will start with 1.
This formula follows your image layout, putting values into column A with data in columns B and C. Please replace the ranges in the formula for columns A and C to cover all of your data. (Ideally, you would do this by inserting a table first and then selecting the data rows, which will cause Excel to put in the table column name instead.)
This is the formula to go into cell A2, assuming you have data in B2:C7
=IF(ISERROR(MATCH(B2,$C$2:$C$7,0)),1,INDEX($A$2:$A$7,MATCH(B2,$C$2:$C$7,0))+1)
Put this formula in D2 and fill down to identify which rows are the ends of sequences:
=ISERROR(MATCH(C2,$B$2:$B$7,0))
Put this formula in E2 and fill down to identify duplicates in the Front column:
=COUNTIF(B$2:B$7,B2)
You can then fill it right one column to also identify duplicates in Back.

Resources