+ Reply to Thread
Results 1 to 7 of 7

Code works the 1st time, but not the 2nd time

  1. #1
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Code works the 1st time, but not the 2nd time

    This code just works on the first time because when It's activated again, It'll try to sum a function, not the value from this function.

    For example:
    First try
    User enters 100 on J" & lrTest - 1 &
    G6 = 0
    Then it'll be =sum (0, 100) that is equal 100.
    But on the second try it'll try to sum the function and won't go on.

    Please Login or Register  to view this content.
    What can I do to solve it?

    Ps: I guess you don't know the full code, but if needed, I can post it.

    This is my workbook:
    cbb2d65.png
    Last edited by luizmachado; 01-17-2016 at 08:41 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Logic problem

    That code doesn't compile.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Logic problem

    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem - not what you think the answer might be. (think google search terms?). Once you have done this please send me a PM and I will remove this request. (Also, include a link to your thread - copy from the address bar)

    Many members search our previous posts, and thread titles play a big part of the search. I doubt anybody would do a search based on your title?

    To change a Title on your post, click EDIT POST then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (note: this change is not optional )
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Logic problem

    I don't follow your description.

    Remove the quotes from around the "G6" in the formula.

    Please Login or Register  to view this content.
    But then the code is putting a formula in cell G6 and the formula references cell G6 which creates a circular reference.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Re: Logic problem

    I should work like a "count" function. For example: every time the code runs this function, It should add 1 to itself (count = count + 1). In my case, every time the code runs through this "code" (because that's just a copy/paste from the full code - which I think It won't be needed. If it does, I can post it here), J&lastrow -1 should be added to G6. So it would be, basically, G6 = G6 + J&lastrow - 1 (-1 because I don't need the last row, but the row before the last one).

    Ps: I need it to change the G6 data when I change something on J column. So I think it needs to be a function.
    Last edited by luizmachado; 01-17-2016 at 08:23 PM.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Logic problem

    Perhaps something like this...

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Re: Logic problem

    It worked!! Thank you!!
    Quote Originally Posted by AlphaFrog View Post
    Perhaps something like this...

    Please Login or Register  to view this content.

+ 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. Logic formula problem
    By Ironhorse1211 in forum Excel General
    Replies: 4
    Last Post: 05-27-2014, 02:59 PM
  2. Logic Problem
    By TamH in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-18-2013, 11:21 PM
  3. Conditional logic problem
    By jparsons18054 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 06-25-2012, 12:03 PM
  4. Fuzzy Logic Problem
    By flyme8 in forum Excel General
    Replies: 2
    Last Post: 05-25-2012, 04:39 AM
  5. If formula logic problem
    By Yobari in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2009, 11:03 AM
  6. logic problem: help needed
    By dcleave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2005, 11:05 AM
  7. Logic Problem
    By JOn Kunces via OfficeKB.com in forum Excel General
    Replies: 4
    Last Post: 07-14-2005, 12: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