+ Reply to Thread
Results 1 to 16 of 16

Insert formula from VBA to worksheet

  1. #1
    Forum Contributor
    Join Date
    03-12-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    138

    Insert formula from VBA to worksheet

    Hi

    I'm trying to insert a formula using the following VBA but it's not working.

    Please Login or Register  to view this content.
    Any ideas as to where the error is please.

    Thanks in advance
    Last edited by jeffreybrown; 02-26-2017 at 05:32 PM. Reason: Use code tags please!

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert formula help

    Hello
    It is working well for me
    Please Login or Register  to view this content.
    What is the text is C8 cell?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Insert formula help

    One thing to try...
    • Place the formula in a worksheet cell
    • Turn on the macro recorder
    • Select F2
    • Select tab
    • Turn off recorder

    Now the formula will be recorded in VBA with the proper syntax; however, it will be recorded as R1C1 notation, but just change the R1C1 to the regular C8 reference
    HTH
    Regards, Jeff

  4. #4
    Forum Contributor
    Join Date
    03-12-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    138

    Re: Insert formula help

    Thankyou

    I see where it went wrong and it's working fine now but I am having trouble with the following now.
    Please Login or Register  to view this content.
    It returns VALUE instead of trimming A8
    Last edited by jeffreybrown; 02-26-2017 at 05:48 PM.

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Insert formula from VBA to worksheet

    I used this :

    Please Login or Register  to view this content.
    Note: there are no spaces before or after the hyphen ""-""

    I also formatted the cells as TEXT.

    Is this what you are after ?

  6. #6
    Forum Contributor
    Join Date
    03-12-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    138

    Re: Insert formula from VBA to worksheet

    Hi

    Thanks for your help

    Sample below if this helps explain
    Attached Files Attached Files

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Insert formula from VBA to worksheet

    Why are you using +0 in the Formula?

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Insert formula from VBA to worksheet

    Did you look at the solution offered in post #5?

    Works for me with using that solution in-place of your current substitute.

    Actually, convert Column A to number and then use...

    Please Login or Register  to view this content.
    Now you don't need the Trim
    Last edited by jeffreybrown; 02-26-2017 at 06:06 PM.

  9. #9
    Forum Contributor
    Join Date
    03-12-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    138

    Re: Insert formula from VBA to worksheet

    Hi Winon

    The +0 converts the texts in column S to texts. The formula in C6 wouldn't work with out it due the trimmed data I believe.

    @MarvinP helped me with it.

    I'm very new to all this , just trying to make my job easier and learn along the way

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Insert formula from VBA to worksheet

    On second thought...

    Please Login or Register  to view this content.

  11. #11
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Insert formula from VBA to worksheet

    Does this help ?
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    03-12-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    138

    Re: Insert formula from VBA to worksheet

    Sorry ... slightly confusing me now.

    Do I need spaces before and after ""-"" or not need spaces. If the latter, I think that's how it is already

    I don't really understand the Dim LR parts if I'm completely honest either. So sorry to be a pain

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Insert formula from VBA to worksheet

    Neither one works for me!

    Both;

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Returns a "#Value!" Error!

  14. #14
    Forum Contributor
    Join Date
    03-12-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    138

    Re: Insert formula from VBA to worksheet

    So it seems to be working now. For some reason like @Logit suggested there were spaces before and after the ""-"". After I removed these it now will insert the Trim formula. Fluke on my part but its working at the mo

    Thankyou all for your help and input

  15. #15
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Insert formula from VBA to worksheet

    Great ! Good job.

  16. #16
    Forum Contributor
    Join Date
    03-12-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    138

    Re: Insert formula from VBA to worksheet

    Thanks.

    Like I said I am very new to this and it does become quite daunting at times but little bits are becoming clearer the more I try, but I would be absolutely stuck with out the help you get from people on this forum

    Thankyou 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. Formula to insert the current page numbers in each row of worksheet
    By mrichard in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-19-2016, 05:41 PM
  2. Insert worksheet name as variable in formula
    By krabople in forum Excel General
    Replies: 4
    Last Post: 09-15-2015, 04:49 PM
  3. Replies: 6
    Last Post: 10-02-2014, 06:31 AM
  4. Formula to match data calculate a value and insert on another worksheet
    By Sharonits in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-05-2013, 09:31 AM
  5. Insert Rows in Worksheet depending on Duplicate Entries in Another Worksheet
    By jimmy_nora in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2010, 06:31 AM
  6. Looking up values on seperate worksheet to insert in formula
    By Tim Hardison in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-09-2009, 10:40 PM
  7. Can I auto insert a worksheet when I insert a value in a cell.
    By iainc in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-27-2006, 03:40 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