+ Reply to Thread
Results 1 to 3 of 3

Division within a macro

  1. #1
    Registered User
    Join Date
    05-21-2019
    Location
    Cleveland, Ohio
    MS-Off Ver
    Office 16
    Posts
    12

    Division within a macro

    I have implemented a macro into my worksheet and I need to divide some numbers, it keeps giving me an error or a 0 value when I run the macro. The division looks like this:
    Sub divcalc()

    Dim Number_1 As Integer
    Dim Number_2 As Integer
    Dim Answer As Integer
    Number_1 = 22
    Number_2 = 2
    Answer = Number_1 / Number_2

    Worksheets("MIP").Range("K2").Value = Answer


    End Sub

    Now when I run this it works fine. However the "22" needs to actually be cell H21. so the division needs to look like this: Answer = H21 / 2
    H21 is a formula that pulls a number from another tab in the worksheet, which changes based on data entered elsewhere. SO H21 is subject to change thats why it needs to be a formula.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Division within a macro

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Division within a macro

    Hallo yarks16
    In future please be so kind and read the forum rules...here
    Your post does not comply with rule #2
    2. Programming code must be enclosed in code tags to improve readability. (A, Z)
    Please Login or Register  to view this content.
    (or use the # button)
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Division by zero
    By raulge91 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-22-2015, 02:21 PM
  2. IF= division
    By TrainGirl in forum Excel General
    Replies: 2
    Last Post: 10-01-2014, 04:51 PM
  3. Macro for division with absolute cell references to replace Indirect formula?
    By naira in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-14-2013, 01:37 AM
  4. [SOLVED] Simple macro for multiplication/division
    By Oilandgasmonkey in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-07-2012, 07:29 PM
  5. division gives wrong answer (division)
    By Brice in forum Excel General
    Replies: 5
    Last Post: 12-24-2010, 10:13 PM
  6. Recursive division Macro Mod needed for Char Type
    By zeph2323 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-12-2008, 10:21 AM

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