+ Reply to Thread
Results 1 to 4 of 4

Kill the Script

Hybrid View

  1. #1
    Registered User
    Join Date
    06-29-2008
    Location
    Perth, Australia
    MS-Off Ver
    MS Office 2003
    Posts
    87

    Kill the Script


    I have a button activated macro, which does a bit of Goal Seeking.
    Sub Solve()
    
       Range("DR19").GoalSeek Goal:=Range("DR22"), ChangingCell:=Range("DQ7")
       Application.Wait (Now + TimeValue("0:00:01"))
       Run macro:="Delete_Trim"
    
    End Sub
    But I want this Macro to work, only if cell EY3 has the value of 2. If cell EY3 has the value of 1, and the user clicked the button that activated the macro, I want the script to warn the user and then die a natural death. So I amended the code to:
    Sub Solve()
    With Target
       If .Address = "$EY$3" And .Formula = "1" Then
       MsgBox "You are trimming in one hold only. This button is deactivated"
    Exit Sub
    Else:
       Range("DR19").GoalSeek Goal:=Range("DR22"), ChangingCell:=Range("DQ7")
       Application.Wait (Now + TimeValue("0:00:01"))
       Run macro:="Delete_Trim"
       End If
    End With
    End Sub
    But the code does not want to work. I have tried a few combinations, but no joy. It is no secret that I am not a VBA person.

    So can someone amend this code so that, if the value of cell EY3 is 1 and some clicked the button, he/she would get the warning (MsgBox), and after clicking 'OK' on the warning, the script would die.

    Thanks in advance.

    Last edited by BazzaBoy; 08-24-2009 at 10:25 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Kill the Script

    You can't use "target" in a regular manually activated macro, at least it's not standard to try. You need to name your objects directly.
    Sub Solve()
       If Range("E3") = 1 Then
           MsgBox "You are trimming in one hold only. This button is deactivated"
           Exit Sub
       Else
           Range("DR19").GoalSeek Goal:=Range("DR22"), ChangingCell:=Range("DQ7")
       Application.Wait (Now + TimeValue("0:00:01"))
       Run macro:="Delete_Trim"
       End If
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Kill the Script

    Hello BazzaBoy,

    Unless you have declared the variable Target as Public at the top of your module, this code won't work. I am assuming this cell $EY$3 is on the ActiveSheet. If so change your code to this...
    Sub Solve()
    
       If Range( "$EY$3").Value  = "1" Then
          MsgBox "You are trimming in one hold only. This button is deactivated"
          Exit Sub
       Else:
          Range("DR19").GoalSeek Goal:=Range("DR22"), ChangingCell:=Range("DQ7")
          Application.Wait (Now + TimeValue("0:00:01"))
          Run macro:="Delete_Trim"
      End If
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    06-29-2008
    Location
    Perth, Australia
    MS-Off Ver
    MS Office 2003
    Posts
    87

    Re: Kill the Script

    Thanks Leith,

    It worked fine. Couln't understand what you meant by

    Unless you have declared the variable Target as Public at the top of your module
    but that's OK, as long as the script works (and dies with dignity).

    Well, if we couldn't succeed in making that button disappear, I had to tackle it some other way.

    Best Regards.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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