Constrains a number between a minimum and maximum value
=MIN(MAX(value, min_value), max_value)This function limits a numeric value so it never goes below a minimum or above a maximum. It's useful for bounding scores, percentages, inputs to formulas, or any calculation where values should stay within a safe range. For example, if A2 contains "120", B2 contains "0", and C2 contains "100", then =CLAMP(A2, B2, C2) returns "100". If A3 contains "-5" with the same limits, it returns "0".
Use the inputs below to create CLAMP as a reusable custom function in Google Sheets.
Learn how to add custom functions to Google SheetsCLAMP
Constrains a number between a minimum and maximum value
=MIN(MAX(value, min_value), max_value)
value
min_value
max_value
Number to clamp
A2
Minimum allowed value
B2
Maximum allowed value
C2
Other functions in the same category: Mathematical & Statistical
Calculates body mass index (BMI) from weight and height
Returns the sigmoid of a number (logistic function)
Calculates Basal Metabolic Rate using the revised Harris-Benedict equation in imperial units
Calculates Basal Metabolic Rate using the revised Harris-Benedict equation in metric units
Calculate the percentage change between two values
Calculates a rolling average over a range using a fixed window size
Named functions enable the creation of custom, reusable formulas that mimic built-in functions, streamlining calculations and data manipulations. These functions simplify complex formulas, making spreadsheets more readable and less prone to errors. By encapsulating intricate logic within a single function call, they enhance consistency across your data. Utilizing named functions reduces the need to write lengthy formulas repeatedly, thereby improving workflow efficiency and productivity in data analysis and management.
Download and import — fastest way to add the function but does not include argument descriptions and examples
Follow these simple steps to download and import a function into your spreadsheet. This method is the quickest and easiest way to add the named function to your Google Sheets document, but will not include the argument description and examples.
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.
Copy and paste — copy and paste each property one at a time
Follow these simple steps to integrate a custom named function into your spreadsheet:
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.