james potter
New Member
- Joined
- Aug 15, 2005
- Messages
- 45
Hello,
I have made a vba code which will run a macro when a certain cell is being modify. I have duplicates this code for several cell in the sheet. In the code only the absolute reference of the cell change. Is there a way to make those reference variable so that there less code necessary?
I have made a vba code which will run a macro when a certain cell is being modify. I have duplicates this code for several cell in the sheet. In the code only the absolute reference of the cell change. Is there a way to make those reference variable so that there less code necessary?
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$K$7" Then
Application.EnableEvents = False
Target = Now
Application.EnableEvents = True
Call report_b7
If Target.Address = "$M$7" Then
Application.EnableEvents = False
Target = Now
Application.EnableEvents = True
Call cobras_b7
End If
Sub cobras_b7()
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
With objMail
.To = Format(Range("$J$7"))
.Subject = "Cobras Charts " & Format(Range("$B$7"))
.Body = "text" & Chr(13) & Chr(13) & "text" & Format(Range("$B$7")) & _
"text" & Chr(13) & Chr(13) & Chr(13) & "text" _
& Chr(13) & "text"
.Display
SendKeys "^{end}"
End With
Set objMail = Nothing
Set objOL = Nothing
End Sub
Sub report_b7()
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
With objMail
.To = Format(Range("$J$7"))
.Subject = "text " & Format(Range("$B$7"))
.Body = "text" & Chr(13) & Chr(13) & "text" & Format(Range("$B$7")) & _
" text" & Chr(13) & Chr(13) & Chr(13) & "text" _
& Chr(13) & "text"
.Display
SendKeys "^{end}"