Results 1 to 14 of 14

display sumif items in messagebox

Threaded View

installer69 display sumif items in... 11-26-2010, 05:18 PM
TMS Re: display sumif items in... 11-26-2010, 08:11 PM
6StringJazzer Re: display sumif items in... 11-26-2010, 08:53 PM
installer69 Re: display sumif items in... 11-27-2010, 04:42 AM
installer69 Re: display sumif items in... 11-27-2010, 09:05 AM
installer69 Re: display sumif items in... 11-27-2010, 03:40 PM
mikerickson Re: display sumif items in... 11-27-2010, 05:02 PM
installer69 Re: display sumif items in... 11-27-2010, 05:17 PM
mikerickson Re: display sumif items in... 11-27-2010, 05:27 PM
installer69 Re: display sumif items in... 11-27-2010, 05:50 PM
installer69 Re: display sumif items in... 11-27-2010, 06:48 PM
mikerickson Re: display sumif items in... 11-27-2010, 11:26 PM
installer69 Re: display sumif items in... 11-28-2010, 04:29 AM
installer69 Re: display sumif items in... 11-28-2010, 06:25 AM
  1. #1
    Registered User
    Join Date
    11-26-2010
    Location
    kent uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    display sumif items in messagebox

    I have a problem that I hope someone can help with. I have a sheet that gives a total using a sumif and I want to popup a message box that contains the values of the cells that were called by the sumif.

    I have the code that will list all the cells in the range but not just the ones called by the sumif.

    I have attached a screenshot of the sheet and the VBA code is below.

    I have looked at precedents but in my real spreadsheet the sumif criteria key is on another sheet.

    In the picture attached A8 contains the value SUM=(A1:A7) but should contain =SUMIF(B1:B7,D1,A1:A7) and the msgbox should contain a list of the values picked up.

    Private Function RangeToString(ByRef rngDisplay As Range, ByVal strSeparator As String) As String
    
        'The string to separate elements on the message box,
        'if the range size is more than one cell
        
        Dim strMessage      As String
        Dim astrMessage()   As String
        
        Dim avarRange()     As Variant
        Dim varElement      As Variant
        
        Dim i               As Long
        
        'If the range is only one cell, we will return that that
        If rngDisplay.Cells.Count = 1 Then
    
            strMessage = rngDisplay.Value
        
        'Else the range is multiple cells, so we need to concatenate their values
        Else
        
            'Assign range to a variant array
            avarRange = rngDisplay
            
            'Loop through each element to build a one-dimensional array of the range
            For Each varElement In avarRange
            
                ReDim Preserve astrMessage(i)
                astrMessage(i) = CStr(varElement)
                i = 1 + i
                
            Next varElement
            
            'Build the string to return
            strMessage = Join(astrMessage, strSeparator)
            
        End If
        
        RangeToString = strMessage
        
    End Function
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        If Target.Address(True, True, xlA1) = "$A$8" Then
        MsgBox RangeToString(Sheet2.Range("A1:A7"), vbCrLf), , "Items"
        End If
    End Sub
    Attached Images Attached Images
    Last edited by installer69; 11-26-2010 at 05:23 PM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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