If/Else conditions assigned to an image to run various actions

stilton1

New Member
Joined
Feb 4, 2019
Messages
6
I created an inventory workbook with various images used as buttons each with their own macro assigned. I have one button named EMAIL that the user clicks and it uses VBA to create an email populating the body of the message which works great. I've added a new section and want to assign the EMAIL button an action based on certain parameters but not sure if it's possible.

For example I'd have an if/else statement to decide between 3 different options based on the content. The EMAIL button would be assigned action A, B or C accordingly. Otherwise, I would need to create 3 different EMAIL buttons and hope the user clicks the correct one.

Any help would be appreciated.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Could you post your existing code (that "works great") and also advise what are the 3 conditions that you want the code to decide between?
 
Upvote 0
For example I'd have an if/else statement to decide between 3 different options based on the content. The EMAIL button would be assigned action A, B or C accordingly.
Though I'm not any expert at VBA but occasionally experiment with what information I draw from net mixed with my needs...
  • I think the IF part should be in your VBA itself.
  • Once a macro is run it should decide in background what actions to take...
The other work around is, the one I use the most -
  • Let excel choose based on Information I give and compose a final version
  • And macro only sends the final message
It all depends on what kind of logical test you want Excel to go through and at what stage...
 
Upvote 0
Solution
I didn't think about using the VBA to use the conditional statement to assign the correct code and set it that way.

Sub EmailDistroSelection()

'Determine Email Distro
If Sheet3.Range("S29") = Sheet3.Range("S49") Then
Sheet3.Range("U29") = Sheet3.Range("U49")
Sheet3.Range("U30") = Sheet3.Range("U50")
Exit Sub
ElseIf Sheet3.Range("S29") = Sheet3.Range("S52") Then
Sheet3.Range("U29") = Sheet3.Range("U52")
Sheet3.Range("U30") = Sheet3.Range("U53")
Exit Sub
ElseIf Sheet3.Range("S29") = Sheet3.Range("S55") Then
Sheet3.Range("U29") = Sheet3.Range("U55")
Sheet3.Range("U30") = Sheet3.Range("U56")
Exit Sub
ElseIf Sheet3.Range("S29") = Sheet3.Range("S58") Then
Sheet3.Range("U29") = Sheet3.Range("U58")
Sheet3.Range("U30") = Sheet3.Range("U50")
Exit Sub
End If
End Sub

I have a drop-down selection on a sheet that ultimately determines who needs to receive a copy by email. On another sheet I have a vlookup that adds all of the TO emails in one cell and CC emails in another cell. The code listed compares the selection criteria and populates the proper email TO and FROM cells as part of a larger subroutine verifying data is entered correctly before generating the email. It may not be efficient code but seems to work well.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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