how can i add a count into my code for email

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
hi I have the 2 codes below but i want them to be added into the same module, as the count code below is in a command button and the email one is in a module how can i combine both codes into the module please?
Code:
Private Sub CommandButton8_Click()
Range("Z1").Value = Range("Z1").Value + 1
End Sub

HTML:
Sub Mail_Selection_Range_Outlook_Body()

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
' Only send the visible cells in the selection.

Set rng = Sheets("Handover").Range("H5:M5").SpecialCells(xlCellTypeVisible)


With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With



Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)



With OutMail
    .To = ThisWorkbook.Sheets("Email Links").Range("A2").Value
    .CC = ""
    .BCC = ""
    .Subject = "Chaser please on this job as the MT has called"
    .HTMLBody = RangetoHTML(rng)

    .Display
End With
On Error GoTo 0

With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Wild Guess/Try - But... maybe...

Rich (BB code):
Private Sub CommandButton8_Click()
Range("Z1").Value = Range("Z1").Value + 1
Call Mail_Selection_Range_Outlook_Body
End Sub
 
Upvote 0
Hi that works great thank you, just wondering though I am only trying to copy selected cells over to another sheet called Chase, for example H5:I5:J5 upto P5 but its not copying the selected cells, the who rows all the way to bottom, can you help please
Code:
Private Sub CommandButton8_Click()
Range("Z1").Value = Range("Z1").Value + 1
Sheets("Handover").Range("H5:I5:J5:K5:L5:M5:N5:O5:P5" & Sheets("Handover").Range("H5:I5:J5:K5:L5:M5:N5:O5:P5").Find("*", , xlValues, , xlByRows, xlPrevious).Row).Copy Sheets("Chase").Range("A2")
Call Mail_Selection_Range_Outlook_Body
End Sub
 
Upvote 0
HI I have also tried chaning it to H5:P5 but it still copies the whole sheet down to the last entry, just wondering how I only copy across specific cells? hope you can help?
 
Upvote 0
Hi,

if you use '*' in .Find then I believe it is looking for the last populated row in the sheet so you can use it when you are copying a range to an unknown row number.
And I don't understand the reason for having the range twice in that bit of coded with & between.

If it's just a row range you are copying then try:
Code:
Sheets("Handover").Range("H5:P5").Copy Sheets("Chase").Range("A2")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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