+ Reply to Thread
Results 1 to 12 of 12

Apply formula through a range of data

  1. #1
    Registered User
    Join Date
    03-12-2015
    Location
    Illinois
    MS-Off Ver
    2013
    Posts
    22

    Question Apply formula through a range of data

    Hello,

    I am extremely new at using VBA so I apologize if my problem seems trivial. I am trying to find a way to apply a formula through a range of data. I started off by applying the formula to single cells. How would I alter the code to apply to a range from B15:2514, C15:2514, D15:2514 and E15:2514 and to then display the final result in cells G15:2514?

    Thank you in advance!

    Please Login or Register  to view this content.
    Last edited by meghs918; 03-22-2015 at 05:30 PM.

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Apply formula through a range of data

    Try adding :Column Letter2514 to each range in the code. Ex.
    Please Login or Register  to view this content.
    Hmm....I'm missing something but not sure what. The code isn't working for me as I expected it to.
    Last edited by gmr4evr1; 03-22-2015 at 05:06 PM.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    03-12-2015
    Location
    Illinois
    MS-Off Ver
    2013
    Posts
    22

    Re: Apply formula through a range of data

    Thanks for the quick reply!

    I did that for each B, C, D, E and G and it would just highlight the range in the G column. It still only gives me the distance for G15.

    I think I need some sort of loop or counter but I have no idea how to code that.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Apply formula through a range of data

    Maybe one way:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    03-12-2015
    Location
    Illinois
    MS-Off Ver
    2013
    Posts
    22

    Re: Apply formula through a range of data

    Thanks TMS! That worked perfectly. I just has to update my formula to take the abs() and everything came out great!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Apply formula through a range of data

    Or, if you want the formulae:

    Please Login or Register  to view this content.

    Regards, TMS

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Apply formula through a range of data

    Or, if you want the values without the loop:

    Please Login or Register  to view this content.

    Regards, TMS

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Apply formula through a range of data

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  9. #9
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Apply formula through a range of data

    Thank you TMS! I messed up and added a loop at the end of the code. Guess what, it wouldn't STOP running, had to end task to get it to stop. And to think, I just told someone today that I know enough about VBA code to mess it up bad.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Apply formula through a range of data

    @meghs918: You're welcome. Thanks for the rep.

    @gmr4evr1: You're also welcome. Thanks for the rep too.

    The problem with your first attempt was that it simply puts the (same) calculated value in every cell in the range. So, you either need to loop through the range and output the value calculated for each iteration. Or, alternatively, just drop the formula into every cell. Note that the cell references will automatically adjust provided you start with the right entries. And, once you have that, it's a small step to convert all the formulae to values.


    Regards, TMS

  11. #11
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Apply formula through a range of data

    You're welcome, and thank you for the new information.
    As long as I don't loop like I tried to, I should be ok.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Apply formula through a range of data

    It happens ... to us all

+ 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. [SOLVED] VBA Apply Formula to All Cells In Range
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-20-2014, 09:25 AM
  2. Replies: 4
    Last Post: 10-02-2013, 09:39 AM
  3. Replies: 1
    Last Post: 01-23-2013, 03:00 PM
  4. Excel 2007 : Apply formula to value depending on range
    By jordanb in forum Excel General
    Replies: 1
    Last Post: 10-03-2011, 09:24 PM
  5. How do I apply the ROUNDUP formula to a range of calculated data
    By IslandGreenHouse in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-28-2005, 06:05 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