+ Reply to Thread
Results 1 to 23 of 23

Populating rows with formulas when new data is entered

  1. #1
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Populating rows with formulas when new data is entered

    I think I have bitten off more than I can chew on this project so any assistance would be greatly appreciated.

    To start things off let me show you the format set up.

    A-Date, B-Client name, C-Product, D-# of units bot, E-price paid

    These are the places that a user will enter data. The data supplied will feed formulas starting in col AA-AQ so there is a bunch of formulas.
    Here is the rub- Each day the data USED to do the formulas (not the input of the user) changes so at the end of each DAY the day’s data (I assume) needs to be saved as value only so the new data does not affect the results of previous days.
    So I have two questions I guess:
    1) How do I add a NEW row of formulas for when a user enters new data (I assume that if I just copy down the formulas all the way down the page and have them fill in when data is entered in A-E but the formulas are long and I think that would bog down the speed hugely right? So what I was thinking was if you started to enter the data in a new row somehow a macro would notice that the last empty row in A has something in it and nothing in row AA so place the formulas in all of the AA-AQ.
    2) At the end of the day I assume another macro would look for the last row of info copy them all and then copy and paste as value only? Again- I don’t know how to do that. In concept I think I get it but coding I do not know.
    Anything anyone can do to help me with this would be greatly appreciated.
    Last edited by sungen99; 05-12-2015 at 08:32 AM. Reason: Bad title

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Bitten off more than I can chew.

    If you could provide an example worksheet explaining and showing what you are trying to do, that would help a lot.

  3. #3
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Bitten off more than I can chew.

    Understood.

    In the attached file.
    B1-B4 can change at anytime. As you can see A11-A13 is for 5/10 and had different input values in B1-B4 and you can see that the numbers in J11-M13 are numbers and NOT formulas like J14-M14 which is using the numbers in B1-B4 to compute.

    What will happen however if tomorrow B1-B4 WILL change and i dont want J14-M-14 to reflect the new numbers.

    So what I believe I need are 2 macros:
    1) a macro that at the of the day (or better yet when i change ANY number ins B1-B4) to save J11-M(whatever is the last line of data) as values
    2) a macro that knows when i enter data into A15 and then creates the formulas that currently reside in J14-M14.

    Again thank you for your help with this. Its above my know how to do.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Bitten off more than I can chew.

    or better yet when i change ANY number ins B1-B4
    I don't think you want to do that, because the Worksheet_Change event doesn't remember the previous value once you entered a new value.So you'd have to have the code create temp values in some blank cells somewhere upon entering a cell, then use those temp values when _Change is triggered. I guess it's doable, but I think having a button you could press to change the formulas to values would be a lot better. Let me know if that approach is ok.

    a macro that knows when i enter data into A15 and then creates the formulas that currently reside in J14-M14.
    This is easy to do and I'll implement it as a Worksheet_Change event, so as soon as you enter the date, the formulas will appear.

  5. #5
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Bitten off more than I can chew.

    so long as you do things exactly as you described this should work:
    Please Login or Register  to view this content.
    added to the worksheet object in your workbook. If you change a value in B1:B4, all the values in the last row of your J:M information become hard coded values. if you add any information in A:E, those formulas will be input into J:M. the risk here is if you add a date without changing anything in B1:B4 then your former last row will never become values it will always be formulas... does that need to change?


    ***EDIT***
    on second thought, why don't we just hardcode everything whenever you change a value in B1:B4... that way the risk i mentioned above goes away:
    Please Login or Register  to view this content.
    Last edited by simarui; 05-11-2015 at 10:39 AM.
    Hope I could help - if your post has been solved don't forget to mark it as such.

    Clicking the * below is a great way to say thanks!

    "Drowning in 10 feet of water isn?t any different than drowning in a million feet. And if you can swim, it doesn?t matter how deep the ocean is. At some level, once you realize you?re in water that?s too deep to stand, you have to have a very different approach," - Joi Ito

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Bitten off more than I can chew.

    @simarui: I like your code, but how I understand the problem is that sungen99 wants to preserve J:M with the values of the formulas before changes were made to B1:B4.

    That's why I'm suggesting a button. Add a button, assign the sungen99 macro to it. Then before making any changes to B1-B4, press the button, and the last line of formulas will be preserved as values.

    The second sub adds the formulas to J:M any time you change a cell in column A, row greater than 10.


    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: Bitten off more than I can chew.

    sungen99,
    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

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

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ben Van Johnson

  8. #8
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Bitten off more than I can chew.

    Thank you all for your assistance with this. Very helpful. Walruseggman’s example is the closest to what I am looking for but upon some testing I found an error but also a new request.

    If noticed that if I add more than 2 lines of new data before running the macro that it does not save the value of the 1st one and leaves it as the formulas.

    That being said. What would be helpful is instead of a button. Would there be a way that upon closing of the program that it could run the macro then exit??? I would not need a button then at all making it easier for the user.

  9. #9
    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
    52,939

    Re: Bitten off more than I can chew.

    sungen99 Please do not ignore requests by Administrators, Moderators and senior forum members regarding forum rules

    All participants:
    Please do not post a reply in a thread where a moderator has requested an action that has not yet been complied with e.g Title change or Code tags...etc. Thanks.
    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

  10. #10
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Bitten off more than I can chew.

    Moderators:
    Check the log as i followed protonLeah request yesterday but when i went to post it said your message needs to be more than 10 words and is too short. Please tell me what to do and i would be happy to comply. I wanted to rename it "populating rows with formulas when new data is entered"

  11. #11
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,604

    Re: populating rows with formulas when new data is entered

    title changed.

  12. #12
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    I actually did it too Zbor... Ha.... apparently i also needed to copy the entire message as well. Thanks for your help.

  13. #13
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    Ok now that has been taken care of back to my post.

    Thank you all for your assistance with this. Very helpful. Walruseggman’s example is the closest to what I am looking for but upon some testing I found an error but also a new request.

    If noticed that if I add more than 2 lines of new data before running the macro that it does not save the value of the 1st one and leaves it as the formulas.

    That being said. What would be helpful is instead of a button. Would there be a way that upon closing of the program that it could run the macro then exit??? I would not need a button then at all making it easier for the user.

  14. #14
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Populating rows with formulas when new data is entered

    Here you go.

    This sub belongs in the ThisWorkbook object (you may need to change "Sheet1" to match whatever the sheet name is with the dates/formulas on it):

    Please Login or Register  to view this content.
    And this code belongs on the sheet object with the formulas:

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    WOW walruseggman this is exactly what i am looking for. Now i just need to enter the real formulas with the real data (which is going to take forever- HA) but it will work.... so great!!!!! thank you!

  16. #16
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    Again thank you all for your assistance on this but I need to tweak the code a little more or at least get a better understanding of the code so I can hopefully do it myself.
    First to give you an update…. I have two new constants… A5 is L# and A6 is M#

    Instead of col A being the deciding factor to full the formulas in I need it to be D.
    If you enter data in D it will complete the formula set up like it does now but it will also add the value (it’s a date) from Constant A5 to the current A row as well at the constant M# form A6 will automatically be copied into the current B row.
    What I am trying to do is to remove as much of the repetitiveness from the user so simplify adding of data.
    Thank you.

  17. #17
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    AHHHH i got it... not that stupid afterall.. hehe..


    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Column = 3 And Target.Row > 10 Then
    r = Target.Row
    Range("A" & r).Formula = "*$B$5"
    Range("B" & r).Formula = "*$B$6"
    Range("J" & r).Formula = "=E" & r & "*$B$1"
    Range("K" & r).Formula = "=J" & r & "*E" & r & "/$B$2"
    Range("L" & r).Formula = "=J" & r & "*$B$3/$B$1"
    Range("M" & r).Formula = "=SUM(J" & r & ":L" & r & ")/$B$4"
    End If
    End Sub

  18. #18
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    I now understand the concepts given in the examples above and am about to start the real coding. I have run into a bit of a snag and require just a little more assistance.
    What would the code structure be for the 3 examples below? Its all just a bit confusing to me and I have A LOT of formulas to code so I want to be sure that its doing what I expect. Hehe..
    Thanks again!

    =SMALL($AB$4:$AB$12, COUNTIF($AB$4:$AB$12,"<"&(BV16))+1)

    =VLOOKUP(CG16,$AD$4:$AE$12,2,FALSE)

    =IF(BL16>0,(((AO16-$AI$9)*$AI$10)*-1),0)+IF(Y16="Heifer",AI11,0)

  19. #19
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Populating rows with formulas when new data is entered

    You'll have to give me context. For example, in your first equation, what's the relationship between BV16 and the cell the formula is in? Are they in the same row? same column? Why BV? etc. etc.

    A workbook sample would be preferred.

  20. #20
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    walruseggman I would send over an workbook sample but I fear that would take me forever to do- it would be easier to just send the actual workbook. Problem with that is I am not “authorized” to give it out as it’s a proprietary program.
    What I CAN tell you is that any line that does not have the “$” absolute assigned to it would be row specific. So for the first one for example:
    =SMALL($AB$4:$AB$12, COUNTIF($AB$4:$AB$12,"<"&(BV16))+1)
    All of this is looking absolute data with the exception of BV16 which would be I assume
    Range("AA" & r).Formula = “SMALL($AB$4:$AB$12, COUNTIF($AB$4:$AB$12,"<"&(BV” & r & “))+1)”
    Is that correct??
    So would =VLOOKUP(CG16,$AD$4:$AE$12,2,FALSE)
    Then be
    Range("AB" & r).Formula = “VLOOKUP(CG” & r & “,$AD$4:$AE$12,2,FALSE)”

    And then
    =IF(BL16>0,(((AO16-$AI$9)*$AI$10)*-1),0)+IF(Y16="Heifer",AI11,0)
    Would be
    Range("AC" & r).Formula = “IF(BL” & r & “>0,(((AO” & r & “-$AI$9)*$AI$10)*-1),0)+IF(Y” & r & “="Heifer",AI11,0)”

  21. #21
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    walruseggman I would send over an workbook sample but I fear that would take me forever to do- it would be easier to just send the actual workbook. Problem with that is I am not “authorized” to give it out as it’s a proprietary program.
    What I CAN tell you is that any line that does not have the “$” absolute assigned to it would be row specific. So for the first one for example:
    =SMALL($AB$4:$AB$12, COUNTIF($AB$4:$AB$12,"<"&(BV16))+1)
    All of this is looking absolute data with the exception of BV16 which would be I assume
    Range("AA" & r).Formula = “SMALL($AB$4:$AB$12, COUNTIF($AB$4:$AB$12,"<"&(BV” & r & “))+1)”
    Is that correct??
    So would =VLOOKUP(CG16,$AD$4:$AE$12,2,FALSE)
    Then be
    Range("AB" & r).Formula = “VLOOKUP(CG” & r & “,$AD$4:$AE$12,2,FALSE)”

    And then
    =IF(BL16>0,(((AO16-$AI$9)*$AI$10)*-1),0)+IF(Y16="Heifer",AI11,0)
    Would be
    Range("AC" & r).Formula = “IF(BL” & r & “>0,(((AO” & r & “-$AI$9)*$AI$10)*-1),0)+IF(Y” & r & “="Heifer",AI11,0)”

  22. #22
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Populating rows with formulas when new data is entered

    Without knowing what you are trying to accomplish with the formulas, all I can say is that the syntax looks correct.

  23. #23
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Populating rows with formulas when new data is entered

    Well thats is at least good news on the way i need to code it. Thank you for all of your help.

+ 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