I have a table in Excel. How can I rotate (NOT transpose) a table 90 degrees clockwise?
Example
cell1 | cell2 | cell3
cell4 | cell5 | cell6
Expected
cell3 | cell6
cell2 | cell5
cell1 | cell4
P/S: If I use transpose option when paste, I will have unexpected result
cell1 | cell4
cell2 | cell5
cell3 | cell6
Thanks
Assuming you want to do this manually, and that it doesn't need to be done via functions:
First transpose your range using the regular copy transpose paste function
Next, create an artificial sorting key (simply number is 1 to n) infront of the first column and sort in a descending order
Delete the sorting column you created in front of the first row
You have to go in a two steps process:
transpose your table (you have already done it)
"mirror" your table
To do this last step, consider that you have a table M rows x N columns, which is transposed into a N rows x M columns. The cell located at row i and column j has to be moved to the row i-1 + N and column j.
In your example, after transposition cell 1 is in (1,1) with N = 3, and it will go to (1-1+3,1)=(3,1) and so on.
You need to use a short macro to do the transformation.
If you can use the new feature of SORTBY in excel,
assuming your table sits in A1:C2, you just need to =SORTBY(TRANSPOSE(A1:C2), TRANSPOSE(COLUMN(A1:C2)),-1) to allow the data sorted by the natural reverse order provided by COLUMN after you transpose it.
Related
I have a data set containing phone numbers three different users. Each one is its own column in Excel. Eg Alice called the numbers in A:A, Bob called the numbers in B:B and Carol called the numbers in C:C (each column is a different length).
I am trying to determine which phone numbers all 3 have called. I have used unique to filter out duplicates from each list and I know how to find duplicate values over two columns using conditional formatting. But how do I find values that ONLY appear in all three columns?
Clarification:
A mockup of the data is as follows (I can't give out the real data):
| 1 | 5656 | 6464 | | | |-----|------|------|---|---| | 2 | 1 | 456 | | | | 456 | 2 | 2 | | | | 345 | 800 | 1 | | |
I want excel to look through the three columns and find any values which are common to all 3 columns and highlight them.
Let's assume the input data is in the range of A2:C7, you can try the following formula in E2:
=LET(rng, A2:C7, ux, UNIQUE(TOCOL(rng,1)),DROP(REDUCE("", ux, LAMBDA(ac, x,
LET(cmp, N(rng=x), ones, SEQUENCE(,ROWS(cmp),1,0), IF(SUM(MMULT(ones, cmp))=3,
VSTACK(ac,x), ac)))),1))
A simplified approach can be achieved using COUNTIFS:
=LET(rng, A2:C7, ux, UNIQUE(TOCOL(rng,1)), FILTER(ux, COUNTIFS(rng,ux)=3))
Here is a sample input data and the corresponding output. Highlighted the numbers the formula should return (see conditional formatting formula below):
The previous solutions assumes there are no repeated numbers per column in the input range (rng). Under this assumption you can define a Conditional formatting as follow:
=SUM(N(A2=$A$2:$C$7))=3
If the number can be repeated within a given column, then the first formula can be adjusted as follow:
=LET(rng, A2:C7, ux, UNIQUE(TOCOL(rng,1)),DROP(REDUCE("", ux, LAMBDA(ac,x,
LET(cmp, N(rng=x), ones, SEQUENCE(,ROWS(cmp),1,0),
IF(SUM(N(MMULT(ones, cmp) >= 1))=3, VSTACK(ac,x), ac)))),1))
Both solutions should work regardless of the number of rows of the input columns. The second input argument of TOCOL(1) ensures empty cells are not taken into account.
You will need to change the ranges, I used just 3 rows to test it.
Sub FindCommonNumbers()
Dim dict As Object
Dim rngAlice As Range, rngBob As Range, rngCarol As Range
Dim cell As Range
Dim phone As Variant
' Create a new dictionary object
Set dict = CreateObject("Scripting.Dictionary")
' Set the range for each user's phone numbers
Set rngAlice = Range("A1:A3")
Set rngBob = Range("B1:B3")
Set rngCarol = Range("C1:C3")
' Add the phone numbers from the first column to the dictionary
For Each cell In rngAlice
dict(cell.Value) = 1
Next cell
' Check the phone numbers in the second column against the dictionary
For Each cell In rngBob
If dict.exists(cell.Value) Then
dict(cell.Value) = dict(cell.Value) + 1
End If
Next cell
' Check the phone numbers in the third column against the dictionary
For Each cell In rngCarol
If dict.exists(cell.Value) Then
dict(cell.Value) = dict(cell.Value) + 1
End If
Next cell
' Print the phone numbers that appear in all three columns
For Each phone In dict.Keys()
If dict(phone) = 3 Then
Debug.Print phone
End If
Next phone
End Sub
I've got a sheet with 4 columns that are drop-down lists which describe an arbitrary product. I need a formula that will assign a numerical value to one of the drop down selections, then sum up all of the numerical values for that row. Across the 4 columns there are 9 criteria that can be selected. I've tried:
=sum((if(b2="x", 1), if(b2="y", 2), if(c2="a", 0.5), if(c2="d", 0.3) and so forth, but the formula is just too long
You need to create a table of data to lookup. You can create it in a new sheet.
x | 1
y | 2
a | 0.5
d | 0.3
The vlookup takes an input e.g. x and looks at the range of the table of data and returns 1
=vlookup(B2,LookupSheet!A1:B5,2,false)
=vlookup([what to look for],[range to search],[column in range to return],[type of search, false means exact match]
What Gary's Student is suggesting is
=sum(vlookup(B2,LookupSheet!$A$1:$B$5,2,false),vlookup(C2,LookupSheet!$A$1:$B$5,2,false))
A |B |C |....|K |L |M |
Tom |0 | |....|Tom |Jim |Dave |
Jim |1000 | |....|15000|14000|12000|
Dave |3000 | |....| | | |
Using Google Sheets for this one. I would like the values in columns K, L, and M to read from column B, detect if the corresponding cell from A reads one of 'Tom', 'Jim', or 'Dave' for example, and then subtract the amount from the correct column to reduce a running total. I've had some trouble figuring it out and tried to use conditional formatting to solve it but can't seem to quite get there. Is there a formula I can use that will read column B and subtract the amount shown from the correct column based on the name in column A?
So to pseudo-code it:
read(column B cell);
if(column B cell - 1 column = "Tom")
{
column K - (value of column B cell)
}
else if(column B cell - 1 column = "Jim")
{
column L - (value of column B cell)
}
etc.
Is there a simple method I can use to generate this result? Also thought about changing the formatting of a cell based on the name in the cell next to it and subtracting the value of any cell with that colour but this becomes unwieldy if names are added. Any assistance would be greatly appreciated!
would there be a way to constrain the formula to a single cell so I can have the total in a single location rather than down the columns? My plan is to have the total boxes scroll with the sheet and always be visible.
Let's assume that Columns A and B continue on down the sheet, with further name + amount entries. You want to have a single row of balances for each of the people.
The balance is then some initial value less the sum of amounts for that person. Say the amounts you've shown in row 2 are the initial values; here's how you could have row 3 reflect the remaining balance for each person (This is for "Tom", copy for the others):
=K2-sumif($A$2:$B,"="&K$1,$B$2:$B)
Alternative solution
This doesn't do exactly what you want, but it is more appropriate for a running total scenario, so others may find it useful to adapt to ledgers, etc.
The IF() function can be used to decide whether or not a value in Column B applies to one of the "total" columns, K to M.
Use this formula in K3, copy to the rest of the range:
=K2-if($A2=K$1,$B2,0)
This example is in Google Sheets, but the same formula works in Excel and other "compatible" offerings.
What you do is put the formula in each column.
Column K subtracts value of column B if column A = "Tom"
Column L subtracts value of column B if column A = "Jim"
etc
I have two input values, that I want to use to return a third value.
Input 1: Y (lets say "Y" is in cell B1)
Input 2: 15 (15 in cell B2)
In another database sheet the input 1 values are sorted in the top row, the input 2 values are listed in a column in front of the wanted values.
| | X | Y | Z |
|16| a | g | k |
|15| b | h | l |
|14| c | i | l |
Fx. X,Y,Z are in row 3 and column 2,3,4.
I want a formula that returns "h" from the two inputs, Y & 15. How is this possible?
In your example above:
=INDIRECT(B1&B2) will return the value in [Y15] which is "h"
Assuming 16 is in Row4, please try:
=INDIRECT(CHAR(CODE(B1)-22)&6-MOD(B$2,14))
Here's a formula for you:
=INDEX(MatrixRange,MATCH(RowInput,MatrixStartColumn,0),MATCH(ColumnInput,MatrixStartRow,0))
MatrixRange = whatever the range of your data matrix is (in entirety) so if your data matrix starts in A3 and ends in D20 this would be replaced with A3:D20
RowInput = whatever cell you are getting search value for to find the row of appropriate data (This is Input 2 on your example)
MatrixStartColumn = Whatever column (or range) your Matrix data index starts in (these would be the numbers in your example). If the numbers on the left side of your data example are in Column A, this would be changed to A:A or A1:A50 (or wherever the last value is). The important thing for this is to use a range from the start of the column otherwise your row count will be off. If you must use a sub-range to avoid matches outside of the matrix, be sure to add the appropriate number to the end of the Match statement. For example if you are specifying MatrixStartColumn as "A3:A44", you will need to add +2 for the first 2 rows being skipped (A1 and A2). So the Index statement becomes (MatrixRange,MATCH(RowInput,MatrixStartColumn,0)+2,...
ColumnInput = whatever cell your column search value is in (your Input 1 data)
MatrixStartRow = Same as StartColumn above but for the header index of your matrix (the XYZ letters in your example). Just as above, if you must use only the range of the matrix, be sure to add your offset numbers so you get the right column.
Assuming that your inputs are at B1 (row), and B2 (Column) here is your formula:
=INDEX(B4:D6,MATCH(B1,A4:A6,0),MATCH(B2,B3:D3,0))
Here is how the formulas work:
INDEX(area with values, row , column) returns value based on row and column you provide.
MATCH(value to find, range to search) returns row/column where value was found.
Note that Match will accept only one row or column for 'range to search'.
I have two sheets with same data and I want to compare entire row in two sheets.
On Sheet1 (old data)
Col A | Col B
1001 | My Val 1
2001 | My Val 2
3001 | My Val 3
On Sheet2 (new data)
Col A | Col B | C
3001 | My Val 3 |True
1001 | My New Val 1 |False
2001 | My New Val 2 |False
Instead of trying to think in terms of comparing rows, make the problem simpler. It is easier to compare just a single cell - so first combine your "whole row" into a single cell. This is easy by concatenating all the cells using the & symbol.
Insert a new (hidden) column C on both sheets, that combines the other columns with a formula like:
= A1 & B1
Now you have a summary that is easy to compare, because you are just looking at single cells and a single column.
On your new sheet, insert a new column D that uses VLOOKUP to see if the row exists on sheet 1:
=VLOOKUP( C1, Sheet1!C:C, 1, false)
Now this will give you an error if the row is not found, and will return the row if it is found.
Your new column E (which corresponds to your old column C) can be calculated with:
=NOT( ISERR( D1 ))
Hide unused columns as required.
I started down the path of the accepted answer, concatenating columns. But with 107 columns, this proved to be tedious.
My solution for this was to paste both sheets into one, keeping the columns aligned.
Then, on the Data tab, click Remove Duplicates. If your remaining row count equals your starting row count, they're identical. If they're not, you'll need to filter columns to find the ones that are not the same.