Excel copy rows & colums but skip blanks - excel

How can I copy the contents of this 'table' using a formula (not VBA or manual copy/paste) into a single column with no blanks?
EDIT
The content of the table will be changing so we want something dynamic
So the output would be something like:
Home
About Us
Financial Planning
Accounting Services
Contact Us
Our Company
Superannuation
Personal
Our Lcoation
...
... etc

It's possible to get the result with a single and long array formula, however, I'd prefer a helper column.
Data region: A1:E5
A6, copied down: array formula
={SMALL((IF($A$1:$E$5="";"";ROW($A$1:$E$5)*1000+COLUMN($A$1:$E$5)));ROW()-ROW($A$6)+1)}
The formula is inserted with Ctrl-Shift-Enter from formula window. Curled brackets are inserted by Excel, not by a user.
Row number of a non-blank cell is multiplied by 1000, and column number is added to it, giving a unique number. The solution works if there are no more than 999 columns. The numbers are listed in the growing order.
B6, copied down:
=OFFSET($A$1;INT($A6/1000)-1;$A6-INT($A6/1000)*1000-1)
The number in the helper row is transformed into row and column offset.
Example - Matrix_transposed_to_one_column.xls

Have you tried (down the column you want the data in):
=A1
=A2
=A3
=A4
=A5
=B2
=B3
=B4
=C2
..etc

Related

Cumulative Amounts of Dupe-only Items in a Resultant Sheet

Sheet 1 goes like this:
Sheet 2 should be like this:
ITEMS QUANTITIES
APPLE 4
GUAVA 2
Sorry for writing the spreadsheet in here, as I'm not allowed to include more than 1 image yet.
Suppose you have the following named ranges:
ITEMS being the data in ITEMS column on your Sheet1;
QUANTITY being the data in QUANTITY column on your Sheet1.
Enter the following formula in Cell D2 on your Sheet2:
=IFERROR(INDEX(ITEMS,MATCH(0,COUNTIF($D$1:D1,ITEMS),0)),"")
Please note it is an array formula which requires you to press Ctrl+Shift+Enter upon finishing the formula in the formula bar.
Drag it down until there is no more items showing up.
Then you can enter the following formula in Cell E2 on your Sheet2 and drag it down:
=SUMIF(ITEMS,D2,QUANTITY)
As you can see from the above screenshot, there may be some empty cells in Column D as I used IFERROR to return blank cells if there is no more distinct item. The corresponding quantity will be 0 consequently. You can choose to delete them or hide them on your worksheet.
By the way I am not sure why Pivot Table is out of the picture as it is actually a faster and easier approach than formula and you do not have to worry about the blank cells returned by the formula if the number of unique items is uncertain. All you need to do is to highlight the source data, insert a pivot table, and put the ITEM in Rows and QUANTITY in Values field.
EDIT: Update to also extract unique distinct values:
Enter this formula in cell A2 of Sheet2:
=IFERROR(LOOKUP(2,1/(COUNTIF($A$1:A1,Sheet1!$A$2:$A$300)=0),Sheet1!$A$2:$A$300), "")
Change 300 to the actual last row of your data and copy that formula down until it returns empty cells.
Then just use a regular SUMIF in cell B2 of Sheet2:
=SUMIF(Sheet1!A2:A300, A2, Sheet1!B2:B10)
Then, type whatever fruit you're looking for incell A2 of Sheet2. Continue like this in the following rows for all the fruits you need.

excel SUMIFS only on same date

I'm trying to create a formula in column K which sums all cells that apply , in column J, only when the following conditions are true:
dates are the same in column A
AND client name is the same in column B
For example, in cell K2, I want the sum of J2+J3+J4 because A2=A3=A4 and B2=B3=B4.
K5=J5 only, because there are no other dates with the same client name.
K6=J6+J7 because A6=A7 and B6=B7.
What kind of formula would I use for this? I can't figure out how to do it with a SUMIFS.
I would try using a pivot table with:
The names as row values
The dates as the column values
And funds received using SUM in the values column
Edit
Based on #pnuts comments here is how to get the values in column K. Put this in K2 and drag down.
=IF(OR(COUNTIFS($B$1:B3, B3) = 1, B3 = ""), SUMIFS($J$2:J2, $A$2:A2, A2, $B$2:B2, B2), "")
This formula will give blank values until the formula finds a new client on a new date. However, I still think using pivot table is a better solution.
However, I still find the pivot table
In cell K2 put following formula:
=IF(COUNTIFS($A$2:A2,A2,$B$2:B2,B2)=1,SUMIFS($J$2:$J$10,$A$2:$A$10,A2,$B$2:$B$10,B2),"")
Adjust row 10 value. It will be last row of your actual data.
Copy down as much you need.
EDIT
Uploaded file shows the cause behind formula not working correctly for you. It turned out to be whitespace characters in column B (names) data e.g.
Cell B3: "Moe John" has a trailing space.
Cell B10: Same case with "Doe Jane"
If you want to use above posted formula then all names shall be corrected. Or alternatively to deal with spaces you can adopt below approach.
=IF(COUNTIFS($A$2:A2,A2,$B$2:B2,"*"&TRIM(B2)&"*")=1,SUMIFS($J$2:$J$28,$A$2:$A$28,A2,$B$2:$B$28,B2),"")
Notice the change in COUNTIFS formula where B2 is now replaced with "*"&TRIM(B2)&"*".
Even such formula will take a beating if you have uneven whitespace characters in between your data. I'd suggest normalizing it as much as possible.

Get certain values from complex table

I have a rather complicated data structure in Excel (Google Drive link). I would like to get certain values from this table:
I tried a combination of a row-column INDEX MATCH. However this did not work because I do not know how to locate the desired column.
Any suggestions how to transform this data structure?
Add two helper columns in M and N.
In M4 enter:
=MATCH(H4,A:A,0)
IN N4 enter:
=COUNTIF(A:A,H4)-1+M4
These will return the first and last row numbers for the Group.
Then in J4, array enter:
=INDEX(INDEX(INDEX($D:$D,$M4):INDEX($D:$D,$N4),MATCH(J$3,INDEX($D:$D,$M4):INDEX($D:$D,$N4),0)+1):INDEX($D:$D,$N4),MATCH(1,1/(INDEX(INDEX($B:$B,$M4):INDEX($B:$B,$N4),MATCH(J$3,INDEX($D:$D,$M4):INDEX($D:$D,$N4),0)+1):INDEX($B:$B,$N4)=$I4),0))
Remembering to confirm with Ctrl+Shift+Enter. Then fill across and down as needed.
There's probably a simpler version!
If you can add a helper column A you can do the following
A3: =E4, A4: =E4, A5: =E4, A6: =E4, A7: =E8...
Once you have the first four values you can drag it down for the frist group and then from group 2 drag those four formulas down to the end.
You data will look like this:
Then in Cell K4 you enter the following formula:
=SUMIFS($E$3:$E$26,
$A$3:$A$26, K$3,
$B$3:$B$26, $I4,
$C$3:$C$26, $J4)
Once you have this you can drag it down and right arbitrarily.
The only issue here is getting the Dates into the helper column, the approach above is only easy if all groups are of equal size but I assumed that given the sample data.
This solution does not required working (helper) cells, just a minor adjustment to your output table:
Enter the word Date in cell I3
Then enter this FormulaArray in cell J4 then copy till J7 then to range K4:L7
(Formulas Array are entered by pressing [Ctrl] + [Shift] + [Enter] simultaneously)
=INDEX($D$2:$D$26,
MATCH($H4&$I$3&J$3,$A$2:$A$26&$B$2:$B$26&$D$2:$D$26,0)
+MATCH($I4,OFFSET($B$2:$B$26,
+MATCH($H4&$I$3&J$3,$A$2:$A$26&$B$2:$B$26&$D$2:$D$26,0),0),0))

Series based on row and column combination

I have an Excel with rows and columns as below:
I need to build a series like below in Excel with two columns as shown:
I have a huge data set where rows are dates and columns are data in half hours.
Which would be the best method?
I would suggest using the INDIRECT function thus:
In the column when you want to have the Row labels, put this formula:
=INDIRECT("R" & MOD(ROW()-1, COUNTA(A:A))+2 & "C1",FALSE)
Here A:A refers to the column where your row labels are stored and +2 is offset to the first row with a label.
In the column where you want the Column labels, put:
=INDIRECT("R1C" & ROUNDDOWN((ROW()-1)/COUNTA($B$1:$D$1),0)+2,FALSE)
Here $B$1:$D$1 refers to the range with your column labels, and +2 is again offset to the first column label.
Assuming your data is in the range C7:F12
We’ll need three fields to show the resulting series: Row, Col and Data
Row: in cell H7 enter this formula and copy till the last record:
=IF(EXACT(H6,H$6),1,
IF(EXACT($I7,CHAR(133)),"",
IF($I7=1,SUM(1,H6),H6)))
Col: in cell I7 enter this formula and copy till the last record:
=IF(EXACT(I6,I$6),1,
IF(EXACT(I6,CHAR(133)),CHAR(133),
IF(I6=COLUMNS($C$7:$F$12),
IF(H6=ROWS($C$7:$F$12),CHAR(133),1),
SUM(1,I6))))
Data: in cell J7 enter this formula and copy till the last record:
=IF(EXACT($I7,CHAR(133)),"",
INDEX($C$7:$F$12,$H7,$I7))
The following will produce your results but the array formula will impact calculation lag depending upon the number of rows and column of data in the original data matrix.
    
The array formula¹ in A10 is,
=IFERROR(INDEX(A$2:A$6, MATCH(0, IF(COUNTIF(A$9:A9, A$2:A$6&"")<COUNT($1:$1), 0, 1), 0)), "")
The standard formula in B10 is,
=IF(LEN(A10), INDEX($B$1:INDEX($1:$1, MATCH(1E+99,$1:$1 )), , COUNTIF(A$10:A10, A10)), "")
Data retrieval in C10 is accomplished with,
=INDEX(A:J,MATCH(A10,A:A,0),MATCH(B10,$1:$1,0))
Fill down as necessary.
¹ Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.
Posting a revised answer following sample data provided by user (left prior answer as it might be useful to other users)
Assuming your data is in the range C6:K11
We’ll need four fields to show the resulting series: Row, Col, 'DateandTime`
Row: in cell M7 enter this formula and copy till the last record:
=IF(EXACT(M6,M$6),1,
IF(EXACT($N7,CHAR(133)),"",
IF($N7=1,SUM(1,M6),M6)))
Col: in cell N7 enter this formula and copy till the last record:
=IF(EXACT(N6,N$6),1,
IF(EXACT(N6,CHAR(133)),CHAR(133),
IF(N6=COLUMNS($C$6:$K$6),
IF(M6=ROWS($B$7:$B$11),CHAR(133),1),
SUM(1,N6))))
Date: in cell O7 enter this formula and copy till the last record:
=IF(EXACT($N7,CHAR(133)),"",
INDEX($B$7:$B$11,$M7,0))
Time: in cell P7 enter this formula and copy till the last record:
=IF(EXACT($N7,CHAR(133)),"",
INDEX($C$6:$K$6,0,$N7))
Fields Row and Col can be hidden

Merge two Excel tables Based on matching data in Columns

I've been working on a excel problem, that I need to find an answer for I'll explain it below.
I've Table01 with the Columns :
Group No
Name
Price
I've Table02 with the columns:
Group No
City
Code
I've merged two tables of Table01 & Table02 as shown in the Image03 , But without order.
But,as you see Group No Column is similar in both tables.
What I need is to get the matching rows of Table01 & 02 considering 'Group No' Column.
The Final result is to be seen as the final image.
Is there a way to do this with excel functions ?
Thank You!
Put the table in the second image on Sheet2, columns D to F.
In Sheet1, cell D2 use the formula
=iferror(vlookup($A2,Sheet2!$D$1:$F$100,column(A1),false),"")
copy across and down.
Edit: here is a picture. The data is in two sheets. On Sheet1, enter the formula into cell D2. Then copy the formula across to F2 and then down as many rows as you need.
Teylyn's answer worked great for me, but I had to modify it a bit to get proper results. I want to provide an extended explanation for whoever would need it.
My setup was as follows:
Sheet1: full data of 2014
Sheet2: updated rows for 2015 in A1:D50,
sorted by first column
Sheet3: merged rows
My data does not have a header row
I put the following formula in cell A1 of Sheet3:
=iferror(vlookup(Sheet1!A$1;Sheet2!$A$1:$D$50;column(A1);false);Sheet1!A1)
Read this as follows: Take the value of the first column in Sheet1 (old data). Look up in Sheet2 (updated rows). If present, output the value from the indicated column in Sheet2. On error, output the value for the current column of Sheet1.
Notes:
In my version of the formula, ";" is used as parameter separator instead of ",". That is because I am located in Europe and we use the "," as decimal separator. Change ";" back to "," if you live in a country where "." is the decimal separator.
A$1: means always take column 1 when copying the formula to a cell in a different column. $A$1 means: always take the exact cell A1, even when copying the formula to a different row or column.
After pasting the formula in A1, I extended the range to columns B, C, etc., until the full width of my table was reached. Because of the $-signs used, this gives the following formula's in cells B1, C1, etc.:
=IFERROR(VLOOKUP('Sheet1'!$A1;'Sheet2'!$A$1:$D$50;COLUMN(B1);FALSE);'Sheet1'!B1)
=IFERROR(VLOOKUP('Sheet1'!$A1;'Sheet2'!$A$1:$D$50;COLUMN(C1);FALSE);'Sheet1'!C1)
and so forth. Note that the lookup is still done in the first column. This is because VLOOKUP needs the lookup data to be sorted on the column where the lookup is done. The output column is however the column where the formula is pasted.
Next, select a rectangle in Sheet 3 starting at A1 and having the size of the data in Sheet1 (same number of rows and columns). Press Ctrl-D to copy the formulas of the first row to all selected cells.
Cells A2, A3, etc. will get these formulas:
=IFERROR(VLOOKUP('Sheet1'!$A2;'Sheet2'!$A$1:$D$50;COLUMN(A2);FALSE);'Sheet1'!A2)
=IFERROR(VLOOKUP('Sheet1'!$A3;'Sheet2'!$A$1:$D$50;COLUMN(A3);FALSE);'Sheet1'!A3)
Because of the use of $-signs, the lookup area is constant, but input data is used from the current row.

Resources