VBA Send Email based off cell value

nivster

New Member
Joined
Aug 10, 2021
Messages
7
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi everyone!

I am not familiar with VBA at all, so I'll appreciate all responses :)

I am trying to send an email address based off the cell value in my excel sheet. The body of the email will change depending on what the value is. If the value is under $0, the body of the email will be different than if it is over $0.

I tried looking for if then examples, and see if those would work but I'm not sure if this is the best solution.

I'd appreciate any information or steps that would help me get this :)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Maybe like this
VBA Code:
Sub MM1()
Dim OutApp As Object, OutMail As Object, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
     If Cells(1, 1) < 0 Then ' looks at cell A1
         strbody = "cell value is less than $0 "
        Else
        strbody = "cell value is greater than $0 "
    End If
With OutMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .HTMLBody = strbody
    .Display   'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Upvote 0
Maybe like this
VBA Code:
Sub MM1()
Dim OutApp As Object, OutMail As Object, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
     If Cells(1, 1) < 0 Then ' looks at cell A1
         strbody = "cell value is less than $0 "
        Else
        strbody = "cell value is greater than $0 "
    End If
With OutMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .HTMLBody = strbody
    .Display   'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Do you know how I can input the actual cell value into the email body? So, for example, if it was $100 in cell A1, how can the email body state "There were $100 gains today"
 
Upvote 0
This
VBA Code:
Sub MM1()
Dim OutApp As Object, OutMail As Object, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
     If Cells(1, 1) < 0 Then ' looks at cell A1
         strbody = "Your current balance is $" & Cells(1, 1).Value
        Else
        strbody = "Your current balance is $" & Cells(1, 1).Value
    End If
With OutMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .HTMLBody = strbody
    .Display   'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Upvote 0
Solution
Thank you so much! This is going to make work so much easier. Truly appreciate it :D
 
Upvote 0
So sorry i am new at VB coding too and i have question....the solution above only reads value from 1 cell.
what if you want to retrieve a certain value from a range of cells?
 
Upvote 0
what values and what range of cells.
What are the required conditions?
 
Upvote 0
Hi Michael M,

I actually managed to find the answer to my earlier question.

thank you
 
Upvote 0
Ok, glad you got it worked out...(y):cool:
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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