If one cell is greater than...

sweetkt327

New Member
Joined
May 1, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I'm trying to create a function where if one cell is greater than another, the value inputted will be the lesser of the two cells.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Welcome to the Board!

You should be able to use the MIN function for this, i.e.
Excel Formula:
=MIN(A1,B1)
will return the lesser of A1 and B1.
 
Upvote 0
If the comparison cell is A1, and the input cell is B1 as in Joe4's formula solution, and if you'd like to change the B1 value accordingly during the entry then you can use the following code in the worksheet class module:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$1" Then
        If Target.Value > Target.Offset(, -1).Value Then
            Target.Value = Target.Offset(, -1).Value
        End If
    End If
End Sub

Or, without VBA, you can avoid user to enter a value more than A1 by using data validation.

1714587274369.png
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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