searching cells for specific conditions

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
634
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.
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
What if the second number is bigger thatn the first? ie. 3 For 5.
 

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
634
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
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
 

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
634
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,561
Messages
5,596,853
Members
414,107
Latest member
Tigretto

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
Top