• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need help with an Excel formula

aphex

Moderator<br>All Things Apple
Moderator
Trying to see if this is possible, any help would be appreciated.

I need a formula to look at a row and count if any of the cell's in that row contain part of a list of words defined in a named range.

Simplified Example/ - I would need A2, A3, A4 and A5 to count the number of times (or even just a YES/NO) that the row contains a value in the Named Range defined below. I also need it to count with wildcards, such as where 'Lima, Peru' in C5 is defined, i would need those to count as well as 'Peru' is in the Named Range.

content



I tried multiple countif functions, but as I my defined range is nearly 300 items, its becoming too unwieldy. Any ideas?
 
You could use multiple countif functions on another tab or outside of the print range (one for each cell in named range), then sum them up anywhere you need to display the total.
 
You can try creating an array--

=SUMPRODUCT(LEN($B$2:$E$5)- LEN(SUBSTITUTE($B$2:$E$5,A8,"")))/LEN(A8)
 
You can try creating an array--

=SUMPRODUCT(LEN($B$2:$E$5)- LEN(SUBSTITUTE($B$2:$E$5,A8,"")))/LEN(A8)

Hmmmm, interesting. That seems to look at the entire batch of data from B2 to E5 at one time and search for Peru, is there a way to make it look row by row for any of the available options in the Named Range?
 
How big is the actual table for this? There is a way to do it, but it might be painful if you have a huge array and or named range.
 
This should do it for you. Just need to setup the variables to your table dimensions and you should be good to go. Let me know if you need any other help on it.

Code:
Sub Macro10()
'
' Macro10 Macro
'

'
    Dim toprow As Integer
    Dim bottomrow As Integer
    Dim firstcolumn As Integer
    Dim lastcolumn As Integer
    Dim namedrange As String
    Dim c As Range
    Dim i As Integer
    Dim count As Integer
    Dim findwhat As String
    Dim comparewhat As String
    
    'change these to match your table params
    toprow = 2
    bottomrow = 5
    firstcolumn = 2
    lastcolumn = 5
    namedrange = "name"
    
    For i = toprow To bottomrow
    
        For Each Cell In Range(Cells(i, firstcolumn), Cells(i, lastcolumn))
    
            comparewhat = UCase(Cell.Value)
            
            For Each c In Range(namedrange)
                
                findwhat = UCase(c.Value)

                If InStr(1, comparewhat, findwhat, 1) <> 0 Then
                    count = count + 1
                End If
            
            Next c
    
        Next Cell

    Cells(i, 1).Select
    Cells(i, 1) = count
    count = 0
    
    
    Next i
End Sub
 
This should do it for you. Just need to setup the variables to your table dimensions and you should be good to go. Let me know if you need any other help on it.

Code:
Sub Macro10()
'
' Macro10 Macro
'

'
    Dim toprow As Integer
    Dim bottomrow As Integer
    Dim firstcolumn As Integer
    Dim lastcolumn As Integer
    Dim namedrange As String
    Dim c As Range
    Dim i As Integer
    Dim count As Integer
    Dim findwhat As String
    Dim comparewhat As String
    
    'change these to match your table params
    toprow = 2
    bottomrow = 5
    firstcolumn = 2
    lastcolumn = 5
    namedrange = "name"
    
    For i = toprow To bottomrow
    
        For Each Cell In Range(Cells(i, firstcolumn), Cells(i, lastcolumn))
    
            comparewhat = UCase(Cell.Value)
            
            For Each c In Range(namedrange)
                
                findwhat = UCase(c.Value)

                If InStr(1, comparewhat, findwhat, 1) <> 0 Then
                    count = count + 1
                End If
            
            Next c
    
        Next Cell

    Cells(i, 1).Select
    Cells(i, 1) = count
    count = 0
    
    
    Next i
End Sub


Works PERFECT!!! Thanks a ton!
 
Back
Top