+ Reply to Thread
Results 1 to 5 of 5

Dynamic Formula

  1. #1
    Registered User
    Join Date
    01-19-2007
    Posts
    14

    Dynamic Formula

    I'm using excel 2003 / VBA Editor

    I'm trying to have the following formula entered into a cell, but can't get it passed the debugger.
    Please Login or Register  to view this content.

    I'd like the formula to, as an example, to be evaluated like the following:

    =SUMIF($D$3:$D$197,"<"&DATE(YEAR($D$3),MONTH($D$3),16),H$3:H$197)

    Any thoughts on where I'm going wrong?
    Last edited by VBA Noob; 09-16-2007 at 03:32 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The VBA Formula mixes VBA with Excel Functions which isn't going to work, for example you use End(xlUp).

    You will need to creat Dynamic Named Ranges for the formula instead of tryin to set the range using End(xlUp)
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    01-19-2007
    Posts
    14
    Please remember to wrap code

    I've been able to use mixed (VBA and Excel Formula) coding when inserting a formula into excel via VBA.

    I think the issue is with the component of the formula that requires quotation marks to encapsulate the formula (Criteria section of the SUMIF formula).

    Here is an example of a formula that mixes VBA and Excel Formulas, which isn't far off from what I'm trying to do.
    Please Login or Register  to view this content.
    Last edited by VBA Noob; 09-16-2007 at 04:19 PM.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    If you really only want to limit the range of the data to process, then something like


    Please Login or Register  to view this content.
    I've just taken the current formula and put in the code to find the last row in column D (wasn't sure if column A would produce the right result) and adapted to allow the " to stand in the formula.

    HTH

    rylo

  5. #5
    Registered User
    Join Date
    01-19-2007
    Posts
    14
    Thanks, that did the trick! I did want to use column "A" to determine the row number, but that was any wasy swap.

    Much appreciated.

+ 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