excluding part of text in Email

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
If sheet2 , Col C , contains a value <> 0 for eg -325.65, 985.75 etc , then the text below to be excluded from being in the body of the email

Code:
  Strbody = Strbody & Join(Application.Transpose(Range("R3:R4").Value)) & " - please attend to these amounts " & vbNewLine & vbNewLine



It would be appreciated if someone can provide me with code to be included in my code to do the above
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I guess there are easier ways but I would need to know your data better.

I was unclear whether R3:R4 were on Sheet2 or not. Note my commented If() line.

Code:
Sub Main()
  Dim strBody As String, r As Range, c As Range, tf As Boolean
  
  strBody = "Hello World! "
  
  With Worksheets("Sheet2")
    Set r = .Range("C2", Cells(.Rows.Count, "C").End(xlUp))
    For Each c In r
      If c.Value <> 0 Then
      'If IsNumeric(c.Value) And c.Value <> 0 Then
        tf = True
        Exit For
      End If
    Next c
  End With
  If tf Then _
    strBody = strBody & Join(Application.Transpose(Range("R3:R4").Value)) & _
      " - please attend to these amounts " & vbNewLine & vbNewLine
  
  MsgBox strBody
End Sub
 
Upvote 0
Thanks for the help, Kenneth. Will test tomorrow and let you know
 
Upvote 0
Hi Kenneth

Have tested your code. It works perfectly


Thanks for the help
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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