+ Reply to Thread
Results 1 to 8 of 8

Macro to multiply a no entered in a cell with a constt no then replace with result

  1. #1
    Registered User
    Join Date
    10-02-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Macro to multiply a no entered in a cell with a constt no then replace with result

    Hi,
    I have been trying to write a macro to write a macro to multiply a number when it is entered in the cell with say 2 and replace number with multiplication result.
    For example if I enter 3 in cell A1 and then click somewhere else in sheet then the number in A1 will be replaced by 6 (3*2). I want this to happen for cells in Range A1 to AB1 only. Also if a character is entered no action should take place.
    I wrote down the following code.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Macro to multiply a no entered in a cell with a constt no then replace with resul

    Please Login or Register  to view this content.
    Please take time to read the forum rules

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Macro to multiply a no entered in a cell with a constt no then replace with resul

    Better add some Application.EnableEvents
    or it will cycle
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  4. #4
    Registered User
    Join Date
    10-02-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro to multiply a no entered in a cell with a constt no then replace with resul

    Hi Steffen,

    I appreciate your quick response. I was pondering over this simple problem for last 2 days :-)
    I tried your code but unfortunately it didn't work. Anyway thanks for your effort.

  5. #5
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Macro to multiply a no entered in a cell with a constt no then replace with resul

    Sorry, try this

    And as pike wrote, then disable events so the code doesnt go into en endless loop.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-02-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro to multiply a no entered in a cell with a constt no then replace with resul

    Hi Pike,

    Your code worked perfectly. Thanks for helping. I am new to vba and is learning.

  7. #7
    Registered User
    Join Date
    10-02-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro to multiply a no entered in a cell with a constt no then replace with resul

    Hi Steffen,

    This code worked as I wanted one more thing when I delete the entered numbers by selecting all of them toghether it shows an error "type mismatch error 113". If you can help it.

  8. #8
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Macro to multiply a no entered in a cell with a constt no then replace with resul

    Then use this

    Please Login or Register  to view this content.

+ 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