VBA code required

RPT_22

Board Regular
Joined
Sep 18, 2012
Messages
98
Hi

I use this formula in B27
= ((B20/18.4)*B22)-B22

Is there code which could perform the following?
Code to give error message for 1 & 2
1. If the value entered into B20 is 18.4 or less - Message "Value must be between 18.5 & 80"
2. If the value entered into B22 is less than 500 or greater than 1000 - Message "Value must be between 500 & 1000"
3. If value entered in either B20 & B22 is incorrect then make cell B27 invisible until value is correct in both B20 & B22
4. Code to lock cell B27 so formaula cannot be erased

Thank you
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You don't need VBA for what you're after. You can add Data Validation to both cells B20 & B22, unlock those cells and protect your worksheet.
 
Upvote 0
its possible, but why would you? To distribute it you'd need to send .xlsm files which some email servers dont like (depends on company policies). Steps 1 & 2 are Data Validation rules, Step 3 is conditional formating and Step 4 is protection of your worksheet as mentioned above. Using VBA to do these tasks is not a good use of VBA as it becomes more difficult to maintain.
 
Upvote 0
Regarding your topic there are multiple videos on the internet. For a start take a look over here ...

 
Upvote 0
Options 1 & 2 are self evident when you click on either cell and then choose 'Data Validation' from the Data ribbon.

You can also use Data Validation to prevent data entry in B27 until the others are correct:
1. Click on B27,
2. Click on Data Validation on the Data ribbon.
3. In the 'Allow' box choose 'Custom'.
4. In the Formula box enter: =and(B20>=18.5, B20<=80, B22>=500, B22<=1000) set the error message to something like: 'Unable to enter data here unto 18.5<=B20<=80 and 500<=B22<=1000. Please check those cells and try again'

A Conditional Formatting formula such as =OR(B20<18.5, B20>80, B22<500, B22>1000) can also be used for B27, and then set the format such that the font colour matches the background when any of those conditions is true.

HTH
 
Upvote 0
Solution

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

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