+ Reply to Thread
Results 1 to 17 of 17

Not running macro on automatic calculation

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Not running macro on automatic calculation

    Hi

    I have a cell "H7" which changes from FALSE to TRUE if a check box is ticked, upon doing this i want to email an address located in "L7"

    I can get it to do this but only by going into the cell and pushing enter, to come out of the cell, i need it to do it without having to go into the cell, what is wrong in this code?

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Target.Worksheet.Range("H7")) Is Nothing Then Mail
    End Sub
    Sub Mail()
    Dim OutlookApp As Object
    Dim Mess As Object, Recip
    Recip = [L7].Value
    Set OutlookApp = CreateObject("Outlook.Application")
    Set Mess = OutlookApp.CreateItem(olMailItem)
    With Mess
    .Subject = "Task Completed"
    .Body = "XXXXXX XXXXXX has completed task" & [B7].Value
    .To = Recip
    .Display
    .Send
    End With
    End Sub
    Also the email doesnt pick up & [B7].Value

    Any one got an ideas?

    Thanks

    Dan

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Not running macro on automatic calculation

    Why not use the Checkbox Click event (activex control) for the call to Mail based on the checkbox value? The code depends on whether you used a forms control or an activex control.

    I see no reason for the [B7].value to not work. Most likely, the value is "". Of course the B7 is for the activesheet as is Range("B7").Value.

  3. #3
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    p.s it wasnt the value in b7 i was after it was c7 so that works fine now, haha

  4. #4
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Hi

    Thanks i got the checkbox click event to do what i want it to rather than the change event, so thats good, thanks, but it executes the macro on uncheck too? is there a way to stop this?

  5. #5
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    I now have this which works fine

    Private Sub CheckBox1_Click()
    Dim OutlookApp As Object
    Dim Mess As Object, Recip
    Recip = [L7].Value
    Set OutlookApp = CreateObject("Outlook.Application")
    Set Mess = OutlookApp.CreateItem(olMailItem)
    With Mess
    .Subject = "Task Completed"
    .Body = "XXXXXX XXXXXX has completed task" & " " & Range("C7").Value
    .To = Recip
    .Display
    .Send
    End With
    End Sub
    But works on check and uncheck, there is no Check_Event or Uncheck_Event so how do i stop it from sending the email when its unchecked, i only want it to do it when it is checked?
    Last edited by shiftyspina; 03-13-2014 at 10:45 AM. Reason: Name showing (privacy)

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Not running macro on automatic calculation

    Sounds like you are using a Forms checkbox control. Obviously, your macro that you assign to it would do it. Do you want an example?

  7. #7
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Nope its definately an activex control, the only way i can see it working is if i do an IF arguement followed by a call module...

    I wouldnt mind if you could please?

  8. #8
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Right, this is now more wrong than i originallly thought,

    1st. It is emailing everytime i select a new cell
    2nd. It isnt picking up the next C column value
    3rd. I have to click in column H or another cell before the code is run

    I have attached the sheet, if you wouldnt mind taking a look for me???

    I would really appreciate any help please

    Thanks

    I have left the design mode on so it doesnt keep emialing me every time a cell is clicked on

    Dan
    Attached Files Attached Files

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Not running macro on automatic calculation

    I will look at it but see if this gives you an idea. Be sure to remove your sheet's event code or modify it if you are now trying to get an active row.

    What is the trigger for Mail? Is it checking the checkbox in a row or changing value in a cell or? Rather than the SelectionChange Event, you probably want the Change event if triggered by a manual cell change in value. But then again, trigger by checkbox checked, a cell change, or other. Even for the Change event, more code is needed to make sure the proper trigger is found and executed. Intersect() is typically need as-well-as setting Application properties such as EnableEvents, Calculation, and Screen updating though the first is most important.

    This is your ActiveX checkbox control example:
    Private Sub CheckBox1_Click()
      MsgBox CheckBox1.Enabled
    End Sub
    When coding such things, if you rename your ActiveX checkboxes, that can be handy.

    For Form checkbox controls:
    Sub FormsCheckBoxCheck()
      Dim o As Shape
      Set o = Worksheets("Sheet1").Shapes("Check Box 3")
      With o
        MsgBox "Name: " & .Name & vbLf & "Value: " & .ControlFormat.Value & vbLf & "Checked: " & .ControlFormat.Enabled, vbInformation
      End With
    End Sub
    Last edited by Kenneth Hobson; 03-13-2014 at 12:26 PM.

  10. #10
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Ok great thank you, i will see what i can do with that, im not an expert user on vba and really only know some basic codes, but my reason for trying to do this, is because i wanted to use Sharepoint, but my IT department wont allow the Sharepoint Foundation on our network, so have to try and do something in excel, which requires regular updates to the users of this task sheet.

    I appreciate your help

  11. #11
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    I couldnt quite understand the code you posted yesterday, i do however have the code working, but on every time i click on a new cell, can i only get it to do it once? i thought loop might be able to do this but doesnt seem too.....

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Not running macro on automatic calculation

    I suggest you replace your checkboxes with Forms controls and then assign one macro to all of them using something like this:
    Sub Mail()
    Dim OutlookApp As Object
    Dim Mess As Object, Recip
    Dim lRow as long
    Dim cb as Checkbox
    set cb = activesheet.checkboxes(application.caller)
    if cb.Value <> 0 then
    lRow = cb.topleftcell.row
    Recip = cells(lRow, "L").Value
    Set OutlookApp = CreateObject("Outlook.Application")
    Set Mess = OutlookApp.CreateItem(olMailItem)
    With Mess
    .Subject = "Task Completed"
    .Body = "Daniel Schofield has completed task" & " " & "-" & " " & Cells(lRow, "C").Value
    .To = Recip
    .Display
    .Send
    End With
    end if
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  13. #13
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Thats great!!

    It works all except one thing...... When i check a box say in row 7, it is picking up the email address from row 6, and the task from row 6 too, can you add +1 on to the row?

    i.e. Recip = Cells(lRow + 1, "L").Value
    Cells(lRow + 1, "C").Value

  14. #14
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Dont worry i added the +1 and it works fine thank you very much for your help

  15. #15
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Ok thank you, i will give that a try, thanks for looking at it for me

  16. #16
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Not running macro on automatic calculation

    You could but I suspect that your checkbox is not quite in the cell. It gets the row from the TopLeft of the checkbox clicked.

  17. #17
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Not running macro on automatic calculation

    Ah ok, that would make sense

    I have slightly changed that bit of code to

    Sub Mail()
    Dim OutlookApp As Object
    Dim Mess As Object, Recip
    Dim lRow As Long
    Dim cb As CheckBox
    Set cb = ActiveSheet.CheckBoxes(Application.Caller)
    If cb.Value > 0 Then
    lRow = cb.TopLeftCell.Row
    Recip = Cells(lRow + 1, "L").Value
    Set OutlookApp = CreateObject("Outlook.Application")
    Set Mess = OutlookApp.CreateItem(olMailItem)
    With Mess
    .Subject = "Task Completed"
    .Body = "Daniel Schofield has completed task" & " " & "-" & " " & Cells(lRow + 1, "C").Value
    .To = Recip
    .Display
    .Send
    End With
    End If
    End Sub
    Where it is >0 so checked it sends the email, if it is unchecked it doesnt send an email and it doesnt send an email on me clicking in another cell

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. automatic running macro daily using ontime method
    By yellowpower in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2012, 12:04 PM
  2. Automatic calculation and macro's
    By digger713 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-19-2010, 05:57 PM
  3. Automatic Running Macro
    By titanxt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2008, 01:57 AM
  4. Automatic running of Macro for the whole spreadsheet
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2005, 05:05 PM
  5. [SOLVED] running macro at automatic time intervals
    By tjb in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-28-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1