+ Reply to Thread
Results 1 to 6 of 6

Need guidance in adding formula to my vba code

  1. #1
    Registered User
    Join Date
    03-14-2022
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    2

    Need guidance in adding formula to my vba code

    Hi ExcelForum,

    I am new with VBA macro and I need help with my problem.

    I am trying to add formula to my vba macro I have this code below:
    Public Function AddForumla()


    Dim lastRow As Integer
    Dim sht As Object

    Set sht = ThisWorkbook.Sheets("Payment Breakdown")
    lastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

    Range("D" & lastRow + 1).Formula = "=+SUM(D2:"D" & lastRow)"

    End Function

    I am having trouble in "=+SUM(D2:"D" & lastRow)" part.

    hope someone can guide me accordingly.

    thanks!

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2501
    Posts
    1,436

    Re: Need guidance in adding formula to my vba code

    Try:
    Please Login or Register  to view this content.
    If things don't change they stay the same

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need guidance in adding formula to my vba code

    Wrong code
    Last edited by AB33; 03-14-2022 at 05:59 AM.

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Need guidance in adding formula to my vba code

    Please use code tags when posting code.

    You should be using this:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  5. #5
    Registered User
    Join Date
    03-14-2022
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    2

    Re: Need guidance in adding formula to my vba code

    Hi everyone,

    Thanks for the help.

    it worked

    I have an additional question,

    let say I want to perform these operation in vba macro:

    =+D420-E420-F420-G420-H420-I420-J420-K420

    How can I do that?

    the lastRow 420 is dynamic

    thanks in advance

  6. #6
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2501
    Posts
    1,436

    Re: Need guidance in adding formula to my vba code

    Maybe the attached will help
    Attached Files Attached Files

+ 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. Need guidance to use a formula to do SUM the data from a PIVOT TABLE
    By acsishere in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-01-2021, 07:05 AM
  2. [SOLVED] Guidance with adding cells that only fall into rows that contain certain information
    By mikeoo in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-07-2015, 12:15 PM
  3. [SOLVED] How to format a code in module? Guidance please!
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-10-2015, 04:40 AM
  4. Replies: 9
    Last Post: 11-19-2013, 06:17 AM
  5. Replies: 3
    Last Post: 07-17-2013, 06:19 PM
  6. Formula Guidance
    By Falcon in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-02-2006, 01:10 PM
  7. Guidance needed with a formula
    By sroehl in forum Excel General
    Replies: 4
    Last Post: 10-03-2005, 03: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