writing a macro to transpose 3 columns into 1 row - excel

I have data as below which is 3 columns I need to transpose into 1 row. The row position needs to be changeable as I move down the specimens. I'm not at all familiar with Excel (am using 2013). Any help would be wonderful. I need to do this hundreds of times and cut and paste then transpose takes too long. Any ideas?
-5.13E+01 -1.99E+02 -1.53E+00
-5.86E+01 -2.12E+02 2.05E+00
-6.61E+01 -2.21E+02 7.45E+00
-6.67E+01 -2.34E+02 1.29E+01
-6.38E+01 -2.46E+02 1.57E+01
-3.90E+01 -2.56E+02 2.54E+01
-1.51E+01 -2.44E+02 2.33E+01
-1.02E+00 -2.31E+02 1.23E+01
-8.72E-01 -2.21E+02 4.19E+00
-1.39E+00 -2.10E+02 1.42E+00
-5.88E+00 -2.00E+02 -1.41E+00
-1.08E+01 -1.89E+02 -1.52E+00
6.15E+00 -2.27E+02 -2.09E+01
-3.11E+00 -2.25E+02 -1.97E+01
-1.96E+01 -2.29E+02 -1.00E+01
-2.52E+01 -2.32E+02 -4.73E+00
-4.17E+01 -2.35E+02 2.48E+00
-4.44E+01 -2.46E+02 6.48E+00
-4.22E+01 -2.60E+02 1.02E+01
-5.32E+01 -2.30E+02 2.18E+00
Cheers

I think this works, but I'd recommend checking!:
=IF(COLUMN()<24,INDEX($A$2:$C$21,COLUMN()-3,1),IF(COLUMN()<44,INDEX($A$2:$C$21,COLUMN()-23,2),INDEX($A$2:$C$21,COLUMN()-43,3)))
in D1 and copied across, assuming -5.13E+01 is in A2 and so forth.
(Even if it does, it probably is far from ideal though, just the best offer you've had so far.)

Related

Excel CUBEVALUE & CUBESET count records greater than a number

I am writing a series of queries to my workbook's data model to retrieve the number of documents by Category_Name which are greater than a certain numbers of days old (e.g. >=650).
Currently this formula (entered in celll C3) returns the correct number for a single Days Old value (=3).
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]",
"[EDD_Report_10-01-18].[Days Old].[34]")
How do I return the number of documents for Days Old values >=650?
The worksheet looks like:
A B C
1 Date PL Count of Docs
2 10/1/2018 ALD 3
3 ...
UPDATE: As suggested in #ama 's answer below, the expression in step B did not work.
However, I created a subset of the Days Old values using
=CUBESET("ThisWorkbookDataModel",
"{[EDD_Report_10-01-18].[Days Old].[all].[650]:[EDD_Report_10-01-18].[Days Old].[All].[3647]}")
The cell containing this cubeset is referenced as the third Member_expression of the original CUBEVALUE formula. The limitation is now that the values for the beginning and end must be members of the Days Old set.
This is limiting, in that, I was hoping for a more general test for >=650 and there is no way to guarantee that specific values of Days Old will be in the query.
First time I hear about CUBE, so you got me curious and I did some digging. Definitely not an expert, but here is what I found:
MDX language should allow you to provide value ranges in the form of {[Table].[Field].[All].[LowerBound]:[Table].[Field].[All].[UpperBound]}.
A. Get the total number of entries:
D3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All]")
B. Get the number of entries less than 650:
E3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[0]:[EDD_Report_10-01-18].[Days Old].[All].[649]}")
Note I found something about using .[All].[650].lag(1)} but I think for it to work properly your data might need to be sorted?
C. Substract
C3 =D3-E3
Alternatively, go for the quick and dirty:
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[650]:[EDD_Report_10-01-18].[Days Old].[All].[99999]}")
Hope this helps and do let me know, I am still curious!

Making a vector out of excel columns using python

everyone...
I just started on python a couple of days ago because I require to handle some excel data in order to automatically update the data of certain cells from one file into another.
However, I'm kind of stuck since I have barely programmed before, and it's my first time using python as well, but my job required me to find a solution and I'm trying to make it work even though it's not my field of expertise.
I used the "xlrd library", imported my file and managed to print the columns I'm needing... However, I can't find a way to put those columns into a matrix in order to handle the data like this:
Matrix =[DataColumnA DataColumnG DataColumnH] in the size [nrows x 3]
As for now, I have 3 different outputs for the 3 different columns I need, but I'm trying to join them together into one big matrix.
So far my code looks like this:
import xlrd
workbook = xlrd.open_workbook("190219_serviciosWRAmanualV5.xls");
worksheet = workbook.sheet_by_name("ServiciosDWDM");
workbook2 = xlrd.open_workbook("Potencia2.xlsx");
worksheet2 = workbook2.sheet_by_name("Hoja1");
filas = worksheet.nrows
filas2 = worksheet2.nrows
columnas = worksheet.ncols
for row in range (2, filas):
Equipo_A = worksheet.cell(row,12).value
Client_A = worksheet.cell(row,13).value
Line_A = worksheet.cell(row, 14).value
print (Equipo_A, Line_A, Client_A)
So I have only gotten, as mentioned above, the data in the columns which is what I'm printing which you can see.
What I'm trying to do, or the main thing I need to do is to read the cell of the first row in Column A and look for it in the other excel file... if the names match, I would have to validate that for the same row (in file 1) the data in both the ColumnG and ColumnH is the same as the data in the second file.
If they match I would have to update Column J in the first file with the data from the second file.
My other approach is to retrieve the value of the cell in ColumnA and look for it in the column A of the second file, then I would make an if conditional to see if ColumnsG and H are equal to Column C of 2nd file and so on...
The thing here is, I have no idea how to pin point the position of the cell and extract the data to make the conditional for this second approach.
I'm not sure if by making that matrix my approach is okay or if the second way is better, so any suggestion would be absolutely appreciated.
Thank you in advance!

EXCEL: Find cells via last number

So I need a way to mark the cells where the sequence ends in 4, 5, or 6.
Data
35632
35215
35115
etc.
I don't have an idea of where to start so any help is much appreciated. I know that I can't use the text filters on numbers even if the cell is formatted as text.
You could use one of the following Excel formulas
=OR(MOD(A1,10)=4,MOD(A1,10)=5,MOD(A1,10)=6)
or
=OR(RIGHT(A1)="4",RIGHT(A1)="5",RIGHT(A1)="6")
or (thanks to Scott Craner)
=ISNUMBER(MATCH(--RIGHT(A1),{4,5,6},0))
or
=ISNUMBER(MATCH(MOD(A1,10),{4,5,6},0))
or
=ISNUMBER(FIND(MOD(A1,10),"456"))
or
=ISNUMBER(FIND(RIGHT(A1),"456"))
or
=SUM(IF(MOD(A1,10)={4,5,6},1)) (returns 1 if true, or 0 if false)
OR
=OR(MOD(A1,10)={4,5,6})
Or
=MOD(MOD(A1,10),7)>3
Or
=ABS(RIGHT(A1)-5)<2

Spreadsheet IF Statements of multiple cells outputting string of text

Hey Stackoverflow users,
I have a spreadsheet from a survey I conducted for one of my classes. A big chunk of my spreadsheet is columns of numbers; they represent "strongly agree, agree, neutral, disagree and strongly disagree" and it's for personalities. I want to pick out certain numbers and see IF they are larger than 3 (neutral) and then output in a cell what that personality would be. If the number is less than 3 than it'd be some opposite personality.
I can provide an example with a picture if needed. My main question is...is it possible for a cell to collect data from different cells (not in a range) and output text in a single cell.
I've accomplished one personality.
=IF(M3>3,"Disorganized","Organized")
The only problem is that I am not doing M3=3 is "neutral."
Then I want to do that for 4 other columns and put them all in one cell.
This is the gist of the personality stuff
=IF(J3>3, "Creative", "Convential")
=IF(M3>3, "Disorganized", "Organized")
=IF(P3>3, "Introvert", "Extrovert")
=IF(T3>3, "Rude", "Nice")
=IF(V3>3, "Calm", "Insecure")
I want to get all 5 of them in one function in one cell and have a "both/neutral" output as well. So let's say one surveyee has 5,5,5,5 and 5, then the cell after all of them would say "Creative, Disorganized, Introvert, Rude, Calm." I hope this makes sense. Also, there are other columns between those specific columns.
Thanks for reading this far. Any help is appreciated.
= IF(J3=3,"Neutral", IF(J3>3, "Creative", "Convential")) & ", " &
IF(M3=3,"Neutral", IF(M3>3, "Disorganized","Organized")) & ", " &
...the rest of your formula here

Excel - 2 tables - If 2 cells in a single row match, return another cell of same row

Working with 2 separate data sets (with duplicates)
Dataset is unique identified by an ID.
There may not be an entry for the timestamp I require.
Datasets are quite large, and due to duplicates, can't use vlookup.
Samples:
Table 1:
Device Name|Time Bracket| On/Off?
ID1 |06:20:00 |
ID2 |06:20:00 |
ID3 |06:30:00 |
Table 2:
Device Name |Timestamp |On/Off?
ID1 |06:20:00 |On
ID2 |06:50:00 |Off
ID3 |07:20:00 |Off
What I want to achieve:
I want an if statement to check if:
1) device ID matches AND
2) timestamp matches
If so, return the value of On/Off from Table 2.
If not, then I want it to return the value of the cell above it IF it's the same device, otherwise just put "absent" into the cell.
I thought I could do this with some IF statements like so:
=if(HOUR([#[Time Bracket]]) = HOUR(Table13[#[Timestamp Rounded (GMT)]]) and
minute([#[Time Bracket]]) = minute(Table13[#[Timestamp Rounded (GMT)]]) and
[#[Device Name]]=Table13[#[Device Name]], Table13[#[On/Off?]],
IF([#[Device Name]]=Table13[#[Device Name]], INDIRECT("B" and Rows()-1), "absent"))
(I put some newlines in there for readability)
However, this doesn't seem to resolve at all... what am I doing wrong?
Is this even the correct way of achieving this?
I've also tried something similar with a VLookUp, but that failed horribly.
Thanks all!
To not deal with array formulas or merging strings which, (not in your case) can still be wrong at the end, I suggest the use of COUNTIFS due to the fact, you have a very small amount of outcomes (just on or off)...
for the first table (starting at A1, so the formula is at C2):
=IFERROR(CHOOSE(
OR(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"On"))+
OR(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"Off"))*2
,"On","Off","Error"),IF(A1=[#[Device Name]],C1,"Absent"))
this will also show "Error" of a match for "On" and "Off" is shown... to skip that and increase the speed, you also could use:
=IF(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"On"),"On",
IF(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"Off"),"Off",
IF(A1=[#[Device Name]],C1,"Absent")))
For both the "Device Name" is at column A, "Time Bracket" at column B and "On/Off?" at column C while the table starts at row 1... If that is not the case for you, then change A1 and C1 so they match
(Also inserted line-breaks for better reading)
Picture to show the layout:
I picked the second formula to show how it works... also, this formula should not be able to return 0's... I'm confused
Couple of good suggestions, however using the helper column as suggested in the topic by Scott Craner above worked.
Created a helper column of concat'd device ID and timestamp for both tables, then did a simple VlookUp.
Another lesson learned: Think outside of the box, and go with simple solutions, rather than try + be too clever like I was doing... :)

Resources