#1
|
|||
|
|||
Macro with Multiple If Statements
Hello. I have posted this question to another forum and am reaching out to this one as I have not gotten any replies yet. For anyone interested in helping, please post replies to the other forum at the link below.
https://www.mrexcel.com/forum/excel-...tatements.html I am very new to working with macros and have very little understanding of VBA, so please let me know if I have not provided all needed information. I would like some help in creating a macro that will be assigned to a button. When the user clicks on the button, I would like one of the following to happen. If a value is in B6 only, put that value in B27. If a value is in B8 only, put that value in B27. If a value is in B12 only, put that value in B27. If values are in B8 and B10, put them 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 in B27 separated by a slash B27 (i.e., B6/B10) If a value is in B10, and B6 or B8 are blank, message should say "The number is a required field. Please make the necessary adjustments.” Message box should say "Okay". If values are in B6, B8, B10 or B12, button message should say “You have entered too many numbers. Please make the necessary adjustments.” Message box should say "Okay". If the resultant number in B27 exceeds 30 characters, button message should say "The number exceeds 30 characters. Please shorten the number by entering it directly in B27." Message box should "Okay". |
#2
|
|||
|
|||
This covers the first 7 rules. I'm a little uncertain of rule 8. This is going to apply to all the other rules?
Code:
Sub MoveValues() ' ' MoveValues Macro ' First Seven rules written here. Note I'm using <> and = to determine if the cell has a value/no value. ' If Range("B6").Value <> "" And Range("B8").Value = "" And Range("B12").Value = "" Then Range("B27").Value = Range("B6").Value ElseIf Range("B6").Value = "" And Range("B8").Value <> "" And Range("B12").Value = "" Then Range("B27").Value = Range("B8").Value ElseIf Range("B6").Value = "" And Range("B8").Value = "" And Range("B12").Value <> "" Then Range("B27").Value = Range("B12").Value ElseIf Range("B6").Value = "" And Range("B8").Value <> "" And Range("B10").Value <> "" Then Range("B27").Value = Range("B8").Value & "/" & Range("B10").Value ElseIf Range("B6").Value <> "" And Range("B8").Value = "" And Range("B10").Value <> "" Then Range("B27").Value = Range("B6").Value & "/" & Range("B10").Value ElseIf Range("B6").Value = "" And Range("B8").Value = "" And Range("B10").Value <> "" Then MsgBox "The number is a required field. Please make the necessary adjustments." ElseIf Range("B6").Value <> "" And Range("B8").Value <> "" And Range("B10").Value <> "" And Range("B12").Value <> "" Then MsgBox "You have entered too many numbers. Please make the necessary adjustments." End If End Sub |
#3
|
|||
|
|||
Hello,
Thank you so much for replying, and I'm sorry for not getting back sooner. I have been away and without a computer. Thank you for the question. I realize I hadn't thought it through well enough. Rule 8 would apply to all the other 7 rules, plus if the user manually enters a number in B27 that exceeds 30 characters. Does this answer the question? Thank you again! |
Tags |
button, if statements, macro |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Multiple If statements, | Jamal NUMAN | Excel | 16 | 11-15-2022 11:59 PM |
Using multiple IF statements on a mail merge | ajh19742000 | Mail Merge | 1 | 11-01-2016 06:11 PM |
Help with if then statements | brent chadwick | Word VBA | 35 | 07-25-2015 02:41 PM |
Mailmerge certain text using multiple if statements | Debs | Mail Merge | 4 | 06-19-2014 03:34 AM |
Multiple If statements | bremen22 | Excel | 2 | 10-15-2013 06:37 AM |