searching cells for specific conditions

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
644
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I have data where the word "for" will appear in cells and if two numbers in the cell are the same, then I'd want to return the word "volume" and if the first number is bigger than the second, then I'd want to return the word "value"

To give a simple example, let's assume that

3 for 3 appeared in cell A1 and
5 for 4 appeared in cell A2.

I'd like a formula which returns the word "volume" in cell B1 (because the numbers 3 and 3 are the same in cell A1) BUT returns the word "value" in cell B2 (because 5 is greater than 4).

Does anyone know how to do this? I've pasted the sample data below:

3 for 3
5 for 4

<colgroup><col style="width:48pt" width="64" span="2"> </colgroup><tbody>
</tbody>


Thanks in advance.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
What if the second number is bigger thatn the first? ie. 3 For 5.
 
Upvote 0
Then that should return the word “volume” as well.

Or to make it easier, you can use the letters f and c. So:

3 for 3 (same numbers) = f
3 for 5 (second number greater than first) = f
5 for 4 (first number greater than second) = c

Please let me know if you want me to clarify the question, further.

Thanks in advance.
 
Upvote 0
this assumes the data will start on row two of column A and the results will be in column B

Code:
Sub t()
Dim c As Range, spl As Variant
    With ActiveSheet
        For Each c In .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
            spl = Split(c.Value, " ")
            If UBound(spl) <> 0 Then
                If spl(LBound(spl)) = spl(UBound(spl)) Then
                    c.Offset(, 1) = "f"
                Else
                    c.Offset(, 1) = "c"
                End If
            End If
        Next
    End With
End Sub
 
Upvote 0
Hi JLGWhiz

Thanks for posting the code above.

It worked for the second row ie the character 'c' was returned because 5 is greater than 4.

But it didn't work for the first row? The cell remained blank....

Do you know what may need to be amended?

Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,220
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top