+ Reply to Thread
Results 1 to 14 of 14

Simple macro for multiplication/division

  1. #1
    Registered User
    Join Date
    07-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Simple macro for multiplication/division

    Hey guys,

    I'm trying to write a couple of really simple macros that will multiply or divide any given cell by 5. So I want to basically do =Formula(C6) to get me C6 x 5. Or to =Formula(D5) to get D5/5.

    How would I do this?

    Thanks

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Simple macro for multiplication/division

    Why would you like to use VBA for that?

    It can be done in Excel easaly.

    Another suggestion would be.

    Record it with the macro-recorder and you get the code.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    07-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Simple macro for multiplication/division

    I'm trying to learn and I can't figure out the syntax to apply an operation to any given cell. What's the notation for cell x?

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Simple macro for multiplication/division

    Code such as the following:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Simple macro for multiplication/division

    Quote Originally Posted by BigBas View Post
    Code such as the following:

    Please Login or Register  to view this content.
    But won't that only work for D5, I want to be able to click any cell.

  6. #6
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Simple macro for multiplication/division

    I didn't really understand the request. The code would be:

    Please Login or Register  to view this content.
    Keep in mind, you need an event to fire the code. Is there something in specific you are trying to work towards, or are you strictly looking for the basics?

  7. #7
    Registered User
    Join Date
    07-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Simple macro for multiplication/division

    Quote Originally Posted by BigBas View Post
    I didn't really understand the request. The code would be:

    Please Login or Register  to view this content.
    Keep in mind, you need an event to fire the code. Is there something in specific you are trying to work towards, or are you strictly looking for the basics?
    Ok so I tried
    Function convert()
    convert = ActiveCell * 5
    End Function

    And it didn't work. I want to be able to click a cell, say with a value of 10, insert it into the convert function, and get 50 as a result. So for example, say cell F6 = 10. In another cell I would input =convert(F6) to get 50 in that cell.

  8. #8
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Simple macro for multiplication/division

    Ok, now I better understand. You are setting up a user defined function.

    Try the following code in a standard module
    Please Login or Register  to view this content.
    Then, test it in the spreadsheet. In cell A1, enter the number 10. In cell B1, enter the formula =CONVERT(A1)

    Let me know if this is what you were after

  9. #9
    Registered User
    Join Date
    07-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Simple macro for multiplication/division

    Quote Originally Posted by BigBas View Post
    Ok, now I better understand. You are setting up a user defined function.

    Try the following code in a standard module
    Please Login or Register  to view this content.
    Then, test it in the spreadsheet. In cell A1, enter the number 10. In cell B1, enter the formula =CONVERT(A1)

    Let me know if this is what you were after
    Ok, I think we are understanding each other now, but for some reason when I type in your formula and test it out, the cell keeps returning a value of 0. Am I doing something wrong?

  10. #10
    Registered User
    Join Date
    07-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Simple macro for multiplication/division

    Bump

    thanks for help

  11. #11
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Simple macro for multiplication/division

    Hm, the function worked fine for me. I wonder if maybe Convert is an existing function in Excel 2007 and not in 2003, and it's causing an issue. Try using the following code (just changed the name). Let me know.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    07-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Simple macro for multiplication/division

    Quote Originally Posted by BigBas View Post
    Hm, the function worked fine for me. I wonder if maybe Convert is an existing function in Excel 2007 and not in 2003, and it's causing an issue. Try using the following code (just changed the name). Let me know.

    Please Login or Register  to view this content.
    This worked, thanks so much.

  13. #13
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Simple macro for multiplication/division

    Glad to help! Keep us posted with future requests.

  14. #14
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Simple macro for multiplication/division

    @ Oilandgasmonkey

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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