Format formula for body text code-get syntax error

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,566
Office Version
  1. 2021
Platform
  1. Windows
I have the following code below


Code:
 strBody = "Hi " & Sheets("Consolidated Auto").Range("S2") & vbNewLine & vbNewLine & _
            "Attached, please find " & Sheets("BTR1").Range("A1") & vbNewLine & vbNewLine & _
            "These amount to " & Sheets("BTR1) &format(Range("G1"), "R#,##0.00") & "vbNewLine & vbNewLine & _
            "Please follow up on matters and give me feedback" & vbNewLine & vbNewLine & _
            "Regards" & vbNewLine & vbNewLine & _
            "Howard"

I am trying to get the formula to generate the format value in cell G! to generate the value as for eg R 1,110,415.75 correct

Code:
  "These amount to " & Sheets("BTR1) &format(Range("G1"), "R#,##0.00") & "vbNewLine & vbNewLine & _

I get a syntax error


It would be appreciated if someone could assist me
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
"These amount to " & Sheets("BTR1") & format(Range("G1"), "R#,##0.00") & vbNewLine & vbNewLine & _
 
Upvote 0
HTH Howard...
Code:
"These amount to " & Format(Sheets("BTR1").Range("G" & 1).Value, "R#,##0.00") & vbNewLine & vbNewLine
Dave
 
Upvote 0
Thanks for the response

when running the macro, I get object does'nt suppot this object or method

Kindly test & corrrect


Code:
 strBody = "Hi " & Sheets("BTR1").Range("S2") & vbNewLine & vbNewLine & _
            "Attached, please find " & Sheets("BTR1").Range("A1") & vbNewLine & vbNewLine & _
           "These amount to " & Sheets("BTR1") & Format(Range("G1"), "R#,#0.00") & vbNewLine & vbNewLine & _
            "Please follow up on these matters and give me feedback" & vbNewLine & vbNewLine & _
            "Regards" & vbNewLine & vbNewLine & _
            "Howard"


See Full code below


Code:
 Sub Email()

With Sheets("BTR1")

If .Range("G1") = 0 Then

Exit Sub


Else

End If

End With

Dim File As String, strBody As String

Application.ScreenUpdating = False

Application.DisplayAlerts = False

File = Environ$("temp") & "\" & Format(Range("Q2"), "mmm-yy ") & Format(Now, "dd-mmm-yy h-mm-ss") & ".xlsx"

strBody = "Hi " & Sheets("BTR1").Range("S2") & vbNewLine & vbNewLine & _

"Attached, please find " & Sheets("BTR1").Range("A1") & vbNewLine & vbNewLine & _

"These amount to " & Sheets("BTR1") & Format(Range("G1"), "R#,#0.00") & vbNewLine & vbNewLine & _

"Please follow up on these matters and give me feedback" & vbNewLine & vbNewLine & _

"Regards" & vbNewLine & vbNewLine & _

"Howard"


ActiveWorkbook.Save

Sheets("BTR1").Copy

With ActiveWorkbook

.SaveAs Filename:=File, FileFormat:=51

.Close savechanges:=False

End With

With CreateObject("Outlook.Application").CreateItem(0)

.Display

.to = Join(Application.Transpose(Sheets("BTR1").Range("R2:R5").Value), ";")

.Subject = Sheets("BTR1").Range("A1")

.body = strBody

.Attachments.Add File

'.Send

End With

Kill File

Application.ScreenUpdating = True

Application.DisplayAlerts = True

End Sub
 
Upvote 0
Thanks for the help Dave. My apologies that I overlooked this earlier

Your code works perfectly
 
Upvote 0
These amount to " & Format(Sheets("BTR1").Range("G" & 1).Value, "R#,##0.00") & vbNewLine & vbNewLine
Hi Dave I have a similar type problem with another macro below, where nothing is being generated in the body of the email

Code:
 strBody = strBody & "Attached Please find " & Range("B4") & Format(Sheets("Summary").Range("C" & 1).Value, "mmm-yyyyy") & vbNewLine & vbNewLine

C1 contains the month and year

It would be appreciated if you could amend this
 
Upvote 0
I Think U had too many "y"'s The cells have to have strings, so use the CSTR function. HTH. Dave
Code:
strBody = strBody & "Attached Please find " & CStr(Sheets("Summary").Range("B4").Value) _
      & CStr(Format(Sheets("Summary").Range("C" & 1).Value, "mmm-yyyy")) & vbNewLine & vbNewLine
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,201
Members
449,214
Latest member
mr_ordinaryboy

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