+ Reply to Thread
Results 1 to 5 of 5

add simple formula to cell in vba

Hybrid View

  1. #1
    Registered User
    Join Date
    03-07-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    12

    add simple formula to cell in vba

    just trying to insert code to a cell in vba and not in cell on spreadsheet as i would like to change the value and have it automatically calculated. formula i would like is =b4*b3, my code is not working

    Sub insertformula()
    Dim A As Range
    Dim B As Range
    
    
    Set A = Range("B4")
    Set B = Range("B3")
    
    
    B.Value = B.Value * A.Value
    
    End Sub

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: add simple formula to cell in vba

    Hi,

    I'm not quite clear what you're asking. If all you want to do is have vba enter a formula for you then

    Range("your_range") = "=B4*B3"
    If you want your range to be the result of B4 * B3 then

    Range("Your_range") = Range("A4") * Range("B3")
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    03-07-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: add simple formula to cell in vba

    found error in code but still does not work
    actual code:
    Sub insertformula()
    Range("b4") = Range("b4") * Range("B3")
    End Sub

  4. #4
    Registered User
    Join Date
    03-07-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: add simple formula to cell in vba

    new code still not working
    Sub insertformula()
    Range("b4") = Range("A4") * Range("B3")
    End Sub

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: add simple formula to cell in vba

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

+ 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