+ Reply to Thread
Results 1 to 8 of 8

Sum values in range of text strings based on other values

Hybrid View

  1. #1
    Registered User
    Join Date
    10-05-2013
    Location
    Lancaster, CA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Sum values in range of text strings based on other values

    Hello,
    In the attached file, I'd like to be able to total the numeric values that preceed certain alpha values in text strings. For example, Item #1 includes "5P" while Item #4 includes "1P", so B6 would be 6. I've played with search and mid, but can't figure out how to iterate through multiple rows and keep a running total (without VB).

    Thanks,
    Adam
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Sum values in range of text strings based on other values

    With text to column.

    After that I run the macro below.

    After that I made an pivot table of it.

    See the attached file.

    Please reply.

    Sub CONVERTROWSTOCOL_Oeldere_revisted_with_steps_in_the_columns()
    
    Dim rsht1 As Long, rsht2 As Long, i As Long, col As Long, col2 As Long, wsTest As Worksheet
    
    'check if sheet "ouput" already exist
    
    Const strSheetName As String = "Output"
     
    Set wsTest = Nothing
    On Error Resume Next
    Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
    On Error GoTo 0
     
    If wsTest Is Nothing Then
        Worksheets.Add.Name = strSheetName
    End If
    
       
       With Sheets("Output")
        .UsedRange.ClearContents
        .Range("A1:C1").Value = Array("item", "value", "Letter")
        
        End With
        
        
        rsht1 = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
        rsht2 = Sheets("Output").Range("A" & Rows.Count).End(xlUp).Row
        col = 2
        col2 = 3
        
        For i = 2 To rsht1
           
            Do While Sheets("sheet1").Cells(1, col).Value <> ""
                rsht2 = rsht2 + 1
                Sheets("Output").Range("A" & rsht2).Value = Sheets("sheet1").Range("A" & i).Value
                Sheets("Output").Range("B" & rsht2).Value = Sheets("sheet1").Cells(i, col).Value
                Sheets("Output").Range("C" & rsht2).Value = Sheets("sheet1").Cells(i, col2).Value
         
                col = col + 2
                col2 = col2 + 2
            Loop
            col = 2
            col2 = 3
        Next
      With Sheets("Output")
       
       .Range("C2:C" & .Rows.Count).SpecialCells(4).EntireRow.Delete
       Columns("A:Z").EntireColumn.AutoFit
        
        End With
    End Sub
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    10-05-2013
    Location
    Lancaster, CA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Sum values in range of text strings based on other values

    We're not supposed to run macros on files in my workplace. Is there a way to do this without them?

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Sum values in range of text strings based on other values

    Is there a way to do this without them?
    Maybe by others.

  5. #5
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Sum values in range of text strings based on other values

    Try this array formula

    =SUM(IFERROR(MID(B1:B4,FIND("P",B1:B4)-1,1),0)*1)

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    Change the highlighted portion for varied results
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Sum values in range of text strings based on other values

    With the solution of Ace_XL in the file.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-05-2013
    Location
    Lancaster, CA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Sum values in range of text strings based on other values

    Money! thank you. I could have sworn I tried to reference the range, but it didn't work...guess not.

  8. #8
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Sum values in range of text strings based on other values

    Money! thank you
    Who is money ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Summing values based on strings in a cell
    By MLomas in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-23-2013, 01:46 PM
  2. Display Text Based on Values in Cell Range
    By kythom in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-25-2013, 02:25 PM
  3. [SOLVED] Counting ammount of values within a range based on text
    By nonterrorist in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-07-2012, 09:16 PM
  4. Replies: 2
    Last Post: 06-13-2012, 11:20 AM
  5. Replies: 0
    Last Post: 02-22-2011, 01:56 PM

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