ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   VB code. If statement between two values (https://www.excelbanter.com/excel-worksheet-functions/448152-vbulletin-code-if-statement-between-two-values.html)

nappyjim

VB code. If statement between two values
 
I have a worksheet where a user input a value. There can be 5 different fomulas based on what value the user enters. How do I make a vb script to say

If the value of sheet1 cell A1 is between 1 and 5, do A1-A2.

If the value of sheet1 cell A1 is between 6 and 10, do A1+A2

Ron Rosenfeld[_2_]

VB code. If statement between two values
 
On Sat, 9 Feb 2013 17:22:08 +0000, nappyjim wrote:


I have a worksheet where a user input a value. There can be 5 different
fomulas based on what value the user enters. How do I make a vb script
to say

If the value of sheet1 cell A1 is between 1 and 5, do A1-A2.

If the value of sheet1 cell A1 is between 6 and 10, do A1+A2


Take a look at Help for Select Case

e.g: Select Case UserInput
Case 1 to 5
Result=A1-A2
Case 6 to 10
result = a1+a2
case else
result ="Out Of Range"
End select


All times are GMT +1. The time now is 09:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com