excluding part of text in Email

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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