+ Reply to Thread
Results 1 to 13 of 13

adding equation to cell via VBA code

  1. #1
    Registered User
    Join Date
    12-28-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    54

    adding equation to cell via VBA code

    Hello again,

    Would someone take a look at this code and tell me where I'm going wrong. It's more of a copy and paste code. I started by doing a macros for coding an equation to convert pounds to stones + pounds. Once I got the equation into a VBA code, I tried to use a previous code and have the equation continue to convert the pounds cell to the stones + pounds cell after conversion, unfortunately this is where I've erred as I'm getting error code: 450.

    Here's the code, highlighted is the copy and paste code I tried to use from an earlier code which works like a charm:

    Please Login or Register  to view this content.
    I'm trying to populate all cells that I have assigned for the sterling + pounds equation. When there are no more conversions to do, the code should stop.

    CheerZ!
    Wyldjokre69

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: adding equation to cell via VBA code

    The best part of populating formulas with FormulaR1C1 is that you can extend them as much as you want and apply to as many cell as you want at tyhe same time.

    for example if you want to aply the formula you created to the Range "A1:A10" just type this:

    Please Login or Register  to view this content.
    and you are done!!

  3. #3
    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,366

    Re: adding equation to cell via VBA code

    Be interesting to see what C[-5] gives you in column A ... either an error or if it wraps around. I'd be betting on an error but you ever know.


    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


  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: adding equation to cell via VBA code

    Quote Originally Posted by TMShucks View Post
    Be interesting to see what C[-5] gives you in column A ... either an error or if it wraps around. I'd be betting on an error but you ever know.


    Regards, TMS
    hahhaha I have no idea but I think she user will understand the point. There is no way for me to see where she has the formula with " ActiveCell"

  5. #5
    Registered User
    Join Date
    12-28-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: adding equation to cell via VBA code

    Thanx fredlo, it worked, but is it possible to be able to loop the process where I don't have to keep changing the range should the data exceed the last range I put in.

    CheerZ!
    Wyldjokre69

  6. #6
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: adding equation to cell via VBA code

    where are you trying to place the formula ? what range right now? I suggested column "A" but according to the formula and as suggested by TMShucks its most likely impossible

    That would help me to figure out the whole thing

    Thanks

  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,366

    Re: adding equation to cell via VBA code

    Just checked ... it doesn't error, it wraps around. However, I suspect that isn't the required outcome.

    A1: =CONCATENATE(ROUNDDOWN(XEZ1/14,0), "-", MOD(XEZ1,14))


    Please Login or Register  to view this content.

    Regards, TMS

  8. #8
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: adding equation to cell via VBA code

    Quote Originally Posted by TMShucks View Post
    Just checked ... it doesn't error, it wraps around. However, I suspect that isn't the required outcome.

    A1: =CONCATENATE(ROUNDDOWN(XEZ1/14,0), "-", MOD(XEZ1,14))
    @ TMShucks Oh wow nice you literally meant it wraps around Nice check

    @ Wyldjokre69 or you can use my favorite version using cells to count instead of range. Both solutions TMShucks's and mine will provide the same outcome

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-28-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: adding equation to cell via VBA code

    Fredlo2010 and TMShucks, you guys are brilliant, made the necessary adjustment to the above code and it worked out perfectly.

    Thank you to you both.

    CheerZ!
    Wyldjokre69

  10. #10
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: adding equation to cell via VBA code

    I am glad we were able to help. For the future and to keep good practices in the post and also help other who might stumble across this in their search for possible solutions, please indicate which answer code you picked out of all the possibilities (in this case two) and also the code you obtained at the end after modifying it.

    Thanks

  11. #11
    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,366

    Re: adding equation to cell via VBA code

    @fredlo2010: there's really no difference in the solutions, more a matter of personal taste. I also use the Cells option but usually when I also want the last column and I'll use Cells for consistency.

    Regards, TMS

  12. #12
    Registered User
    Join Date
    12-28-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: adding equation to cell via VBA code

    Hello,

    You are correct, here is the final version of the vbs code I used. You will see as to which version of the code you wrote is the one I used. Had to make the necessary adjustments to fit my spreadsheet, but it's still the same code you guys so brilliant made at least the part of the code I was having problems with:

    Please Login or Register  to view this content.
    Once again I just like to thank y'all for your help and am so glad I found this forum. I'll be going back to check my other solved forum queries and put the final codes on to those as well.

    CheerZ!
    Wyldjokre69

  13. #13
    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,366

    Re: adding equation to cell via VBA code

    You're welcome. Glad we could help. Thanks for the feedback.

+ 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. Adding Text to another cell VB code (Help Tweeking code) (Excel 2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 11:37 AM
  2. Replies: 4
    Last Post: 07-15-2012, 03:03 PM
  3. Replies: 2
    Last Post: 03-17-2011, 08:55 PM
  4. adding a characters at the end of an equation.
    By steven_c in forum Excel General
    Replies: 5
    Last Post: 08-30-2010, 03:45 PM
  5. Please Help: Adding an equation to a range
    By tobriant in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 09-06-2005, 09:05 PM

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