简体   繁体   中英

Excel, Creating new columns based on information in rows

I downloaded some data but it is not in an immediately usable format.

The format is excel.

My dataset looks something like below(the first row is the headings):

CompanyID PaymentMethod Amount
1         Cash          $100
          Stock         $200
2         Cash          $500

In order to be able to analyse the information I require the information to just be one row per company ID. I cannot have multiple rows referring to the same company ID.

I was wondering if there was a code I can use to alter the data so in the end it will look something like this:

CompanyID  PaybyCash PaybyStock
1          $100      $200
2          $500      

Basically it will just copy the values to new columns (and delete the old one).

Thanks in advance :).

One approach would be to use a pivot table. To do this, you would need to do a little work on the data first:

1) Fill in any missing company IDs - one approach would be to use an unused column (eg start with cell D2 and enter the formual:

=if(A2="",A1,A2)

This will use the value in the cell above if the value for that row in column A is empty, but use the value itself if not. Drag the formula down for all rows. You can then check the results and if happy copy and do a paste special (option in righ mouse click) and select values to paste the values from the formula in column D into column A, you can then delete column D.

2) You will need to convert the amounts to a currency field. If you do a find and replace you can just replace the $ with nothing. Then select all of the values in column C and do a right click, select formatls cel and choose currency as the data type.

3) Select all of the data, go to the insert tab and choose create PivotTable. You will have an option of new sheet or existing sheet. Once done drag the Amount into Values, the CompanyID into RowLabels and the PaymentMethod into column labels.

This should get you started at least. It would probably be worth checking out some online tutorials on pivot tables once you have had a quick play with the above to see if it may be what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM