If a text cell contains value greater than

koksalcanberk

New Member
Joined
May 20, 2020
Messages
7
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I want excel to return TRUE if a text cell contains value greater than 2500.

For example, it has to return TRUE for the cell with "John-2504-Doe" in it.

For the cell with "John-2010-Doe" in it, on the other hand, it has to return FALSE.

Is this possible to do?

Best,
C
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Is the numeral in a consistant place in the cell? Always after a fixed number of characters or after a specific character, like - in the OP?
Does the numeral always have the same number of characters?
 
Upvote 0
Is the numeral in a consistant place in the cell? Always after a fixed number of characters or after a specific character, like - in the OP?
Does the numeral always have the same number of characters?

Thank you for your response.

Unfortunately, the answer the both of your questions is "no"...
 
Upvote 0
Welcome to the MrExcel board!

You could consider using a user-defined function. Here are two options. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

The functions have an optional second argument if you wanted to look for a different sized number in the string - see rows 9 & 10.

VBA Code:
Function GreaterThan(s As String, Optional lower As Long = 2500) As Boolean
  Dim RX As Object, M As Object
  
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.Pattern = "\d{" & Len(lower) & "}"
  For Each M In RX.Execute(s)
    If Val(M) > lower Then
      GreaterThan = True
      Exit Function
    End If
  Next M
End Function


Function Greater_Than(s As String, Optional lower As Long = 2500) As Boolean
  Dim i As Long, lng As Long
  
  lng = Len(lower)
  For i = 1 To Len(s) - lng + 1
    If Mid(s, i, lng) Like String(lng, "#") Then
      If Val(Mid(s, i, lng)) > lower Then
        Greater_Than = True
        Exit Function
      End If
    End If
  Next i
End Function

koksalcanberk 2020-05-20 1.xlsm
ABC
1John-2504-DoeTRUETRUE
2John-2010-DoeFALSEFALSE
334joe50doeFALSEFALSE
434joe3550TRUETRUE
545abc 1111-3456TRUETRUE
645abc 1111-2222FALSEFALSE
7
8
9abc6789FALSEFALSE
10abc6790TRUETRUE
Sheet1
Cell Formulas
RangeFormula
B1:B6B1=GreaterThan(A1)
C1:C6C1=Greater_Than(A1)
B9:B10B9=GreaterThan(A9,6789)
C9:C10C9=Greater_Than(A9,6789)
 
Upvote 0
Welcome to the MrExcel board!

You could consider using a user-defined function. Here are two options. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

The functions have an optional second argument if you wanted to look for a different sized number in the string - see rows 9 & 10.

VBA Code:
Function GreaterThan(s As String, Optional lower As Long = 2500) As Boolean
  Dim RX As Object, M As Object

  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.Pattern = "\d{" & Len(lower) & "}"
  For Each M In RX.Execute(s)
    If Val(M) > lower Then
      GreaterThan = True
      Exit Function
    End If
  Next M
End Function


Function Greater_Than(s As String, Optional lower As Long = 2500) As Boolean
  Dim i As Long, lng As Long

  lng = Len(lower)
  For i = 1 To Len(s) - lng + 1
    If Mid(s, i, lng) Like String(lng, "#") Then
      If Val(Mid(s, i, lng)) > lower Then
        Greater_Than = True
        Exit Function
      End If
    End If
  Next i
End Function

koksalcanberk 2020-05-20 1.xlsm
ABC
1John-2504-DoeTRUETRUE
2John-2010-DoeFALSEFALSE
334joe50doeFALSEFALSE
434joe3550TRUETRUE
545abc 1111-3456TRUETRUE
645abc 1111-2222FALSEFALSE
7
8
9abc6789FALSEFALSE
10abc6790TRUETRUE
Sheet1
Cell Formulas
RangeFormula
B1:B6B1=GreaterThan(A1)
C1:C6C1=Greater_Than(A1)
B9:B10B9=GreaterThan(A9,6789)
C9:C10C9=Greater_Than(A9,6789)

First formula did a good job but failed to detect all the cells. But the second formula worked like charm! Thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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