Forum Discussion

Riley Robinson's avatar
Riley Robinson
Copper Contributor
May 05, 2018
Solved

Having VBA Macros upload a formula to a Cell

I'm trying to write a sub routine that identifies a last name from a cell in column B, insert that name into the formula to identify which tab the formula is supposed to work with and continue to do ...
  • Matt Mickle's avatar
    May 06, 2018

    It's difficult to tell exactly what you're trying to do without an example of how your worksheet is set up.  Would it be possible for you to upload a non-sensitive mock up file with fake data in it, so that the community can better understand your scenario?

     

    After skimming your code I noticed that this formula is incorrect:

     

     Hours = "=IF(Last!$B$6>0,(Last!$B$6-Last!$B$5)-SUM(Last!$B$7:$B$10),(IF(Last!$B$5="","",$C$1-Last!$B$5-SUM(Last!$B$7:$B$10))))"

     

    In VBA if you use double quotes like in a worksheet formula you actually need to repeat them 4 times.  So your formula should look like this:

     

    Hours = "=IF(Last!$B$6>0,(Last!$B$6-Last!$B$5)-SUM(Last!$B$7:$B$10),(IF(Last!$B$5="""","""",$C$1-Last!$B$5-SUM(Last!$B$7:$B$10))))"

Resources