+ Reply to Thread
Results 1 to 7 of 7

Ref text in cell in a formula

  1. #1
    Registered User
    Join Date
    11-25-2005
    Posts
    51

    Ref text in cell in a formula

    I have a spreadsheet of all 500 S&P500 stocks. One col has the sector each stock is in (i.e. healthcare, financials, consumer etc..) Another col has the weighting of each stock in the index. I want to add the total weighting for each stock in each sector. So I would be adding the weighting for all stocks in the healthcare sector and all stocks in the industrials and so on. How do I ref the cells with text in a formula to do this? Thanks again.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,787
    Try something like

    =SUMIF(A:A,"healthcare",B:B)

    where column A contains the text and column B the weightings

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    Seems like this will work for you:

    With Sector in Col_A, Weight in Col_B

    =SUMIF(A:A,"Healthcare",B:B)

    Does that help?

    Regards,
    Ron

  4. #4
    Registered User
    Join Date
    11-25-2005
    Posts
    51
    Thank You!!

    That's very close to what I'm looking for but then I would have to type a separate formula for each sector, right? Isn't there a way to tell Excel "If the text in A1:A200 is the same, then count how many cells have that text. And do this for each instance where the text changes and output the result to another cell". In other words, is there a way to ref the text without actually having to enter a separate formula for each instance where the text changes. Hope I'm being clear. My brain hurts from trying to figure this out

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    Perhaps a Pivot Table is the better way to go.

    Data>Pivot Table
    Use Excel
    Select your data
    Click the [Layout] button

    ROW: Drag the Sector field here
    DATA: Drag the Weight field here
    If it doesn't list as Sum of Weight...dbl-click it and set it to Sum
    Click [OK]
    Select where you want the Pivot Table...and you're done!

    That will list each Sector and the Total of the Weights.

    To refresh the Pivot Table, just right click it and select Refresh Data

    Is that something you can work with?

    Regards,
    Ron

  6. #6
    Registered User
    Join Date
    11-25-2005
    Posts
    51
    When I do as you said it gives me a table with sectors in "Row" and "Total" equals the number of stocks in each sector, not the total weighting. The figures I have in the Weighting Col are the percentage that each stock makes up of the total, so the Grand Total should be 100. In this case the Grand Toatal is the sum of stocks in each sector (499).

    The Weighting Col has numbers like .0245%, .0059%, .0061% and so on. So lets say those three numbers were the Weighting for all 3 stocks in a sector (Banks for example). Then the "Total" field for Banks should be the sum of those 3 figures. Instead the Total field is simply the number of stocks in each sector. Thanks again.

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    I'm a bit puzzled.

    Let's say you have 3 columns:
    Sector
    Stock
    Weighting

    Sector: Healthcare, Manufacturing, etc
    Stock: A, B, C, etc
    Weighting: various percents 0.025%, 0.135%, etc
    (the whole Weighting coumn totals to 100%)

    In the Pivot Table:
    Sector is the ROW
    Weighting is the DATA and is set to Sum of Weighting

    The Total Column can only be the sum of percents

    Note: if you put the Stock field into the DATA area, Excel can only use the count because math doesn't work with text fields.

    I think the only way you'd be stuck with a count of the Weighting percents is if they are really text fields masquerading as numbers.

    Example:
    0.0123% is a number
    '0.0123% is a word

    Try this:
    Select the Weighting cells
    Format|Cells|Number tab
    Category: Percentage
    Click the [OK] button

    While those cells are still selected:
    Data|Text-to-Columns
    Click the [Finish] button
    (Those steps should ensure that the Weighting values are truly numeric)

    Refresh the pivot table.

    Any satisfaction?

    Regards,
    Ron

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1