Macro with Multiple If Statements

PosieQ

New Member
Joined
Mar 14, 2017
Messages
8
Hello,

I would like some help in creating a button macro for a spreadsheet that is essentially a user form. The form has four cells in which the user enters requested information in cells B6, B8, B10, or B12. Not all of the cells require a number. When the user clicks on the button, I would like the number or combination of numbers to appear in B27 according to the conditions listed below. Also, if the number in B27 has more than 30 characters, I would like a message box to appear informing the user that the number needs to be (manually) changed in B27.


  • If a number is in cells B6, B8, or B12 only, that number alone should appear in cell B27.
  • If numbers are in B8 and B10, both numbers should appear in B27 separated by a forward slash (i.e., B8/B10).
  • If numbers are in B6 and B10 and B8 is blank, the number in B27 should appear as B6 and B10 separated by a forward slash (i.e., B6/B10).
  • If a number is in B10, it is expected that a number should also be entered in either B6 or B8. Therefore, if a number is in B10 but not in B6 or B8, the button message will say, "You have entered only an Order number. Please enter either an appropriate Schedule No., GWAC No., IDIQ No., or BPA No, or make any other necessary corrections."
  • If a number is entered in all cells (B6, B8, B10, or B12), then button message will say, "You have entered too many numbers. Please delete the extraneous numbers."
  • If the number that shows up in B27 exceeds 30 characters, button message will say, "The contract number exceeds 30 characters. Please shorten the number by entering it directly in B27."


I know this is a bit complicated, and I hope I’ve explained it well. I appreciate any help anyone can give. Thank you.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hello,

I am bumping this post with a few adjustments. Please let me know if I've missed providing any information. Thank you!


  • If value is in B6 only, put that value in B27.
  • If value is in B8 only, put that value in B27.
  • If value is in B12 only, put that value in B27.
  • If values are in B8 and B10, put values in B27 separated by a slash (i.e., B8/B10)
  • If values are in B6 and B10 and B8 is blank, put B6 and B10 separated by a slash in B27 (i.e., B8/B10)
  • If a value is in B10 but B6 or B8 are blank, button message should say "The Contract Number is a required field because you have entered an Order number. Please make the necessary adjustments.” Message box is "Okay".
  • If values are in B6, B8, B10 or B12, button message should say “You have entered too many contract numbers in the General Contract Information section (cells B6-B12). Please make the necessary adjustments.” Message box is "Okay".
  • If the resultant number in B27 exceeds 30 characters, button message should say "The Contract No. exceeds 30 characters. Please shorten the number by entering it directly in B27." Message box is "Okay".
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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