+ Reply to Thread
Results 1 to 7 of 7

automate division to each respective cell

  1. #1
    Registered User
    Join Date
    08-13-2019
    Location
    US
    MS-Off Ver
    360
    Posts
    5

    Question automate division to each respective cell

    So I'm trying to write a macro that will divide H (Force) from G (meters) , up to some "lastrow."
    I tried using this for loop that I thought would translate to each respective cell, but instead it just kept the "=H2/G2" function.
    Code below:

    Please Login or Register  to view this content.
    I cant figure out what I should put for the formula to say that I would want it to go from H2/G2, H3/G3 to "last row" respectively.

    If anyone could help, I'd really appreciate it, thanks.
    Last edited by Glenn Kennedy; 08-13-2019 at 02:38 PM. Reason: Please re-read Rule 2. I have changed it for you, since you are new here.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: automate division to each respective cell

    Unless you are using a bunch of other stuff for the macros, I would recommend using a table. It will auto-fill a formula you put in the first row down to the last row automagically. Highlight your data and hit Ctrl-T.

    Other than that
    Range("I" & i).Formula = "=H"&i&"/G"&i

    Just like you had it on the left side of the equation.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: automate division to each respective cell

    Hello,

    Or you can use the R1C1 formula:

    Please Login or Register  to view this content.
    Or you could avoid loping and use .FillDown after
    Please Login or Register  to view this content.
    much faster as no looping involved!
    Last edited by bulina2k; 08-13-2019 at 02:37 PM.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  4. #4
    Registered User
    Join Date
    08-13-2019
    Location
    US
    MS-Off Ver
    360
    Posts
    5

    Re: automate division to each respective cell

    Pauley,
    Thanks for the response -- I'm planning to average the data after they are averaged and there are a total of 11690 rows, which is prone to fluctuate given the form of data collection.

    Given that number, it seems unfeasible to highlight the columns -- I tried "=H"&i&"/G"&i as well as a couple variations; however I run into the error "expected: End of statement", or some other error.

  5. #5
    Registered User
    Join Date
    08-13-2019
    Location
    US
    MS-Off Ver
    360
    Posts
    5

    Re: automate division to each respective cell

    This worked perfectly, Thanks!

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,425

    Re: automate division to each respective cell

    Quote Originally Posted by bulina2k View Post
    Or you could avoid loping and use .FillDown after
    Please Login or Register  to view this content.
    much faster as no looping involved!
    You could also do this part with a single line of code...
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: automate division to each respective cell

    Quote Originally Posted by josehm View Post
    Given that number, it seems unfeasible to highlight the columns
    Actually, Ctrl-T automatically selects the block of numbers and then brings up a dialog box for you to refine as necessary.


    Quote Originally Posted by josehm View Post
    I tried "=H"&i&"/G"&i as well as a couple variations; however I run into the error "expected: End of statement", or some other error.
    Ahh, yes, I forgot to add spaces around the ampersands. Sounds like you have a solution, but if you see that error again, that's why.
    Last edited by Pauleyb; 08-13-2019 at 04:57 PM.

+ 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. using VBA to calculate input from one cell to the respective values further down.
    By andreasnw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-10-2017, 07:21 AM
  2. Replies: 5
    Last Post: 04-07-2016, 03:34 AM
  3. Replies: 14
    Last Post: 01-25-2015, 06:12 AM
  4. [SOLVED] Row highlighted with respective of cell
    By kumawat_s in forum Excel General
    Replies: 1
    Last Post: 08-14-2014, 07:03 AM
  5. Replies: 15
    Last Post: 08-24-2013, 10:05 AM
  6. a folrula that will place the number in it's respective cell
    By MariaSevak in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-10-2013, 12:47 PM
  7. division gives wrong answer (division)
    By Brice in forum Excel General
    Replies: 5
    Last Post: 12-24-2010, 10:13 PM

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