+ Reply to Thread
Results 1 to 4 of 4

How to write a macro for command button

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2010
    Location
    Glasgow
    MS-Off Ver
    Excel 2002
    Posts
    15

    Post How to write a macro for command button

    Hi,

    I am attempting to set up two command buttons under the headings of series and parallel. If the series command button is hit I would like the contents of cell D3 to be displayed in G3, and if the parallel button is hit I would like the following calculation to be achieved in G3: (1-(1-D3^2)).

    If possible I would also prefer only one command button to be pressed at any one time,

    Hope you can help,

    Regards,

    Charlie

  2. #2
    Registered User
    Join Date
    01-11-2010
    Location
    Glasgow
    MS-Off Ver
    Excel 2002
    Posts
    15

    Post Re: How to write a macro for command button

    Would a toggle button maybe be a better option? If so what code would I use for it?

    Thanks,

    Charlie

  3. #3
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: How to write a macro for command button

    Here is code for the buttons:

    Option Explicit
    
    Sub Parallel()
    
        If Not Range("D3").Value = vbNullString Then
            Range("G3").Formula = "=(1-(1-D3^2))"
        Else
            MsgBox "Cell D3 is empty - please enter a value", vbExclamation
            Exit Sub
        End If
    
    End Sub
    Sub Series()
    
        If Not Range("D3").Value = vbNullString Then
            Range("G3") = Range("D3")
        Else
            MsgBox "Cell D3 is empty - please enter a value", vbExclamation
            Exit Sub
        End If
    
    End Sub
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  4. #4
    Registered User
    Join Date
    01-11-2010
    Location
    Glasgow
    MS-Off Ver
    Excel 2002
    Posts
    15

    Re: How to write a macro for command button

    Thank you, that helps a great deal,

    Charlie

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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