+ Reply to Thread
Results 1 to 6 of 6

Two tasks, same macro?

Hybrid View

OptionTrader Two tasks, same macro? 11-01-2009, 10:09 AM
royUK Re: Two tasks, same macro? 11-01-2009, 10:12 AM
shg Re: Two tasks, same macro? 11-01-2009, 12:54 PM
OptionTrader Re: Two tasks, same macro? 11-01-2009, 01:01 PM
OptionTrader Re: Two tasks, same macro? 11-04-2009, 06:19 AM
shg Re: Two tasks, same macro? 11-04-2009, 01:00 PM
  1. #1
    Registered User
    Join Date
    10-03-2004
    Posts
    70

    Two tasks, same macro?

    I want to put a value in a single cell - A1 is going to be (say) 5.

    Sub Macro()
    Cells(1, 1) = "5"
    End Sub
    Now, if A1 already contains the value 5 I want to change it to (say) 0 using the same macro.

    Sub Macro()
    Cells(1, 1) = "5"
    If Cells(1, 1) = 5 Then
    Cells(1, 1) = 0
    End If
    End Sub
    Clearly doesn't work as the value 0 is always returned.

    I want to link the Macro to a button such that the first click returns 5, click again returns 0, click again returns 5, and so on.....

    How can I do this please ?
    Last edited by OptionTrader; 11-11-2009 at 08:33 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Two tasks, same macro?

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Two tasks, same macro?

    Sub Macro()
        Range("A1").Value = IIf(Range("A1").Value = 0, 5, 0)
    End Sub
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    10-03-2004
    Posts
    70

    Re: Two tasks, same macro?

    Fantastic. Thank you so much!

  5. #5
    Registered User
    Join Date
    10-03-2004
    Posts
    70

    Re: Two tasks, same macro?

    Me again!

    How can I do the same thing, but instead of putting a value in a cell, put a formula.

    e.g.

    Instead of;

    Quote Originally Posted by shg View Post
    Sub Macro()
        Range("A1").Value = IIf(Range("A1").Value = 0, 5, 0)
    End Sub
    I want to do;

    Quote Originally Posted by shg View Post
    Sub Macro()
        Range("A1").Value = IIf(Range("A1").Value = "=A1+A2", "" ,"=A1+A2")
    End Sub
    Doesn't work. Thanks in advance...

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Two tasks, same macro?

    I may be losing the bubble as to what you're trying to do, but maybe this:
    Sub Macro()
        Range("A1").Value = IIf(IsEmpty(Range("A1").Value), "=B1+B2", vbNullString)
    End Sub

+ 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