Excel copy/paste based on duplicate value in column - excel

I need a code to copy/paste based on duplicate cell values in a column. Please see example below. I want to take values from A2:B2 and paste to C1:D1 if there is duplication in E1:E2. Then loop through the rest of the spreadsheet. Any ideas? Thanks :-)
Sample
A B C D E
111 222 ABC
333 444 ABC
555 666 DEF
777 888 DEF
Result
A B C D E
111 222 333 444 ABC
333 444 ABC
555 666 777 888 DEF
777 888 DEF

in Cell C2:
=if(e2=e3,a3,"")
Copy this to every cell in C and D.

Related

Create two new Dataframes from existing one based on unique and repeated values of a column

colA colB
A 125
B 546
C 4586
D 547
A 869
B 789
A 258
E 123
I want to create two new dataframe and the first one should be based on the unique values in 'colA' and the second one should be the repeated values of 'colB'. The colB has no repeated values. The first output is like this:
ColA colB
A 125
B 546
C 4586
D 547
E 123
The second output is like this:
colA colB
A 869
B 789
A 258
For the first group, use drop_duplicates. For second group, use duplicated:
print (df.drop_duplicates("colA"))
colA colB
0 A 125
1 B 546
2 C 4586
3 D 547
7 E 123
print (df[df.duplicated("colA")])
colA colB
4 A 869
5 B 789
6 A 258

Perform computation on a value in one row and update another row's column with that value

I have a dataframe that looks somewhat like :
Categor_1 Categor_2 Numeric_1 Numeric_2 Numeric_3 Numeric_col4 Month
ABC XYZ 3523 454 4354 565 2018-02
ABC XYZ 333 444 123 565 2018-03
qww ggg 3222 568 123 483976 2018-03
I would like to apply some simple math on a column with a condition and assign it to a different row.
For instance
if Month == 2018-03 & Categor_2 == 'XYZ', perform Numeric_3*2 and assign it to Numeric_3 under month 2018-02.
So the output would be something like :
Categor_1 Categor_2 Numeric_1 Numeric_2 Numeric_3_ Adj Numeric_col4 Month
ABC XYZ 3523 454 246 565 2018-02
ABC XYZ 333 444 123 565 2018-03
qww ggg 3222 568 123 483976 2018-03
I was thinking of taking out the necessary columns, then doing a pivot, applying the math, then again reshaping it back in the orginal way.
However if there is a quick way, would be grateful to know
It depends what is length of Series of filtered DataFrame - here is one element Series, so possible set to scalar by next with iter for posible add default value if condition not match:
mask = (df.Month == '2018-03') & (df.Categor_2 == 'XYZ')
print (df.loc[mask, 'Numeric_3'] * 3)
1 369
Name: Numeric_3, dtype: int64
#get first value of Series, if emty Series is returned 0
a = next(iter(df.loc[mask, 'Numeric_3'] * 3), 0)
print (a)
369
df.loc[df.Month == '2018-02', 'Numeric_3'] = a
print (df)
Categor_1 Categor_2 Numeric_1 Numeric_2 Numeric_3 Numeric_col4 Month
0 ABC XYZ 3523 454 369 565 2018-02
1 ABC XYZ 333 444 123 565 2018-03
2 qww ggg 3222 568 123 483976 2018-03

Replacing a value after comparing 2 columns from VLOOKUP

I have to compare SYSIDs in 2 excel sheets and replace SYSID in first sheet with Component ID in 2nd sheet.
First sheet: Second Sheet:
SYSIDS SYSIDS COMPONENT_ID
123 123 111
345 345 222
678 678 333
First sheet Output should be:
SYSIDs:
111
222
333
How can I get it done?
Simple VLOOKUP:
=VLOOKUP(A2,Sheet2!A:B,2,FALSE)

Line up Column B and its Value in Column C with Column A values retaining original order of column A. Puts non-matching column B values below

Please can anyone help out me doing this?
I have two main columns A and B. Column A contains a product code and column B contain its price. Now I have some product code in column C. I need their prices and maintain column C order.
A B C D
110 $10 115
111 $12 120
112 $18 117
113 $13 111
114 $22
115 $24
116 $98
117 $26
118 $77
119 $34
120 $17
Enter the formula in Column D and drag it down,
=IFERROR(INDEX(B:B,MATCH(C1,A:A,0),1),"")

Sort 2 Columns + Adj Column by matching Numbers

I have a long list of ID number in Column C with important information in Column D-Q.
I need to sort it accordingly to a specific set of ID numbers in Column B along with the matching information in Col D-Q, like this:
I have this:
B C D E . . .
123 234 male 12
234 345 female 13
345 555 male 12
444 123 male 11
I need this:
B C D E . . .
123 123 male 11
234 234 male 12
345 345 female 13
444 N/A N/A N/A
Essentially, I need the information from C (and the adjacent info) to match with B or get sorted by the ID numbers in B. The file is huge and I just need to pull/sort it just by a specific set of ID numbers.
Thank you!
EDIT:I tried to use as suggested, the following in a new column. However, I receive the #N/A and #REF error.
=Index(D:Q,Match(B:B, C:C,0)
Provides error: #N/A and #REF!
You can get all the matching data from C-Q using index(array, match()). Just make the match() on B and C.

Resources