Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2017, 06:45 PM
PosieQ PosieQ is offline Macro with Multiple If Statements Windows 7 64bit Macro with Multiple If Statements Office 2007
Novice
Macro with Multiple If Statements
 
Join Date: Mar 2017
Posts: 2
PosieQ is on a distinguished road
Default 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".
Reply With Quote
  #2  
Old 03-29-2017, 09:59 AM
dwirony dwirony is offline Macro with Multiple If Statements Windows 7 64bit Macro with Multiple If Statements Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 49
dwirony will become famous soon enough
Default

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
Reply With Quote
  #3  
Old 04-03-2017, 03:15 PM
PosieQ PosieQ is offline Macro with Multiple If Statements Windows 7 64bit Macro with Multiple If Statements Office 2007
Novice
Macro with Multiple If Statements
 
Join Date: Mar 2017
Posts: 2
PosieQ is on a distinguished road
Default

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!
Reply With Quote
Reply

Tags
button, if statements, macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro with Multiple If Statements Multiple If statements, Jamal NUMAN Excel 16 11-15-2022 11:59 PM
Macro with Multiple If Statements Using multiple IF statements on a mail merge ajh19742000 Mail Merge 1 11-01-2016 06:11 PM
Macro with Multiple If Statements 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft