+ Reply to Thread
Results 1 to 4 of 4

Worksheet.function question

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    2007, 2010
    Posts
    127

    Worksheet.function question

    Hello,

    My question:

    When using the worksheet.function method in VBA, what code would one use to copy the result to all applicable cells in each applicable rows. My code is below:

    Range("M3") = WorksheetFunction.Sum(Range("K3:L3"))
    I need the above result for M4, M5, M6, etc. and I don't want to right the above code multiple times for each row of data. Thanks.
    BrownBoy

    If happy, mark "SOVLED" & add to "REP"

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Worksheet.function question

    Can you post a sample workbook?

    How many rows are you trying to do this for?
    You can do a simple loop or you can simply use a excel function for all of the cells then copy and paste values IF that is something you are looking for.

     Range("M3:M20").Formula = "=Sum(K3:L3)"
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Contributor
    Join Date
    03-06-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    2007, 2010
    Posts
    127

    Re: Worksheet.function question

    Thanks mT,

    Your formula works perfectly. I was under the impression that using the "worksheet.function" property was the preferable method for adding Excel functions when doing VBA. Is that incorrect?

  4. #4
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Worksheet.function question

    So your command entered the value of the sum formula, where my command entered the actual formula into the cells.

+ 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. Turning a function from serving current worksheet to specific worksheet
    By ahmadmasri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-15-2013, 10:15 PM
  2. Using date format and left function with worksheet name to hide worksheet
    By rgullett in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-21-2012, 05:16 PM
  3. A question about the SUMIF worksheet function.
    By mbu in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-31-2008, 12:16 AM
  4. question regarding IF worksheet function
    By shrooms in forum Excel General
    Replies: 2
    Last Post: 12-10-2007, 11:25 AM
  5. [SOLVED] Basic Question - How do I return the worksheet number of the active worksheet?
    By Regnab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2006, 10:10 PM

Tags for this Thread

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