+ Reply to Thread
Results 1 to 5 of 5

Adding Formula to cell in VBA

  1. #1
    Registered User
    Join Date
    01-07-2012
    Location
    Washington DC, USA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Adding Formula to cell in VBA

    I have data being entered from a userform where the row is a variable. My goal would be to add the formula below to a column when data gets entered

    =IF(ISBLANK(C2),"",DATE(YEAR(C2),MONTH(C2),DAY(C2)))

    Please Login or Register  to view this content.
    I can't seem to figure out how to get all the quotation marks correct to make the formula work. Any help would be appreciated.

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

    Re: Adding Formula to cell in VBA

    Something like this

    Please Login or Register  to view this content.
    I'm making a guess the formula in going in D2 and down to the last row of some column.

    Without looping it could also be written as

    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    01-07-2012
    Location
    Washington DC, USA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Adding Formula to cell in VBA

    Thanks that first option was the one I was looking for. It was the R1C1 that I was missing to make this work. Thanks again for the help!

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

    Re: Adding Formula to cell in VBA

    Here is the easiest method to get it right in VBA (at least for me)

    Put the formula in the first cell which in this case is D2.

    Place you cursor on D2 >> turn on macro recorder >> select F2 >> select Enter

    Now open the VBE and look at the new macro that was recorded.

    Doing it this way ensures the right syntax is there everytime

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

    Re: Adding Formula to cell in VBA

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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