+ Reply to Thread
Results 1 to 17 of 17

Script to auto fill cells based on multiple criteria.

  1. #1
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    237

    Question Script to auto fill cells based on multiple criteria.

    See my attached workbook. I need a code that can take the value in Resource Detail:Col A and copy it into each column, starting with the start date through and including the end date which is listed in Resource Detail:Col C and D. So for row 5, it would copy 1.50 to every column from 8/17 to 6/30 which can be found in Row 2. I would also like a way for it to skip columns that are either Sat or Sun (row 1).
    Attached Files Attached Files

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    i'm guessing there's a better way to do this. but this will do the job, I believe:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    237

    Re: Script to auto fill cells based on multiple criteria.

    Since this is a function, how do I use this? Am I putting a formula somewhere on the sheet?

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    Quote Originally Posted by narrowgate88 View Post
    Since this is a function, how do I use this? Am I putting a formula somewhere on the sheet?
    you know that there are 2 primary routine names in this language, right? functions and subs. I don't believe functions can be run directly from button click actions. you will have to change the title of the code routine to sub to get it called that way. functions can run from anywhere => directly from the VB editor by clicking the play button, or they can be called from other places in the code, behind any object. you simply have to make sure either block of code is in the first line of the routine:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    if there is no qualifying statement before the word function, it is visible as ""global"", or what is called ""public"" by the coding environment.

    does that help?

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Script to auto fill cells based on multiple criteria.

    Quote Originally Posted by vba_php View Post
    I don't believe functions can be run directly from button click actions
    FWIW, yes they can.

    I can't really see why this would be written as a function though, when it doesn't return anything.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    Quote Originally Posted by rorya View Post
    FWIW, yes they can.

    I can't really see why this would be written as a function though, when it doesn't return anything.
    thank you! I will remember that. the reason why it is written as a function is because I always post code in the form of a function. I do that so people are learning can always run the code directly in the VBA editor simply by pressing the PLAY button. my code posting has nothing to do with programming standard. but yes, you are correct, and I apologize, if I were being ""proper"", I would obviously only post functions when a returns are justified, and subs when they are not.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Script to auto fill cells based on multiple criteria.

    Quote Originally Posted by vba_php View Post
    I do that so people are learning can always run the code directly in the VBA editor simply by pressing the PLAY button
    You know you can do that with any routine (sub or function) that doesn't require arguments?

  8. #8
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    Quote Originally Posted by rorya View Post
    You know you can do that with any routine (sub or function) that doesn't require arguments?
    well I have never been able to write the following code and push the PLAY button inside the editor when the cursor is sitting in the middle of the routine's code. what do I have to do then?
    Please Login or Register  to view this content.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Script to auto fill cells based on multiple criteria.

    Just give the routine a name.

  10. #10
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    Quote Originally Posted by rorya View Post
    Just give the routine a name.
    ummmm....yeah. so, why hasn't it worked for me!? hmmmm....I just ran a test and it works fine behind any object. hmmmm. thanks rorya

  11. #11
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    237

    Re: Script to auto fill cells based on multiple criteria.

    The code above is not working quite like I need. After converting it to a sub, it's not taking into account the start and end date when it does its for each segment. It's filling them all out through 6/29/21 and it's not ignoring the Sat/Sun columns.

  12. #12
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    237

    Re: Script to auto fill cells based on multiple criteria.

    It also skipped all the F and G columns which seems weird and possibly unrelated to the code.

  13. #13
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    I'm not really sure what you're talkin about or why that's happening for you because I remember distinctly running this on my end and it worked perfectly. can you post the resulting workbook after running the code that was posted?

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,746

    Re: Script to auto fill cells based on multiple criteria.

    I remember distinctly running this on my end and it worked perfectly
    Really
    Nowhere in the code is it looking at the dates & considering you've got MA as the last column, how is this meant to work
    Please Login or Register  to view this content.

  15. #15
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    Quote Originally Posted by Fluff13 View Post
    Really
    Nowhere in the code is it looking at the dates & considering you've got MA as the last column, how is this meant to work
    Please Login or Register  to view this content.
    there's always a possibility I'm wrong Fluff. hmmmmm....it doesn't look like those args are valid, does it? I guess that makes perfect sense. thanks for pointing it out. The OP has not gotten back to anyone in a while. Personally, I'm going to wait until he/she posts the code they ran. by the way, don't I know you from somewhere, Fluff? I believe from another board, but I can't remember which one. Care to jar my memory? I think I know, but....

  16. #16
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,746

    Re: Script to auto fill cells based on multiple criteria.

    don't I know you from somewhere, Fluff? I believe from another board, but I can't remember which one. Care to jar my memory? I think I know, but....
    It was from MrExcel where you posted under the name of ajetrumpet & got banned.

  17. #17
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Script to auto fill cells based on multiple criteria.

    oh yes, now I remember. one of those moderators has a disdain for me. Can't remember who that was, but I do have his picture. but anyway, thanks for the correction again.

+ 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. [SOLVED] Auto fill cells based on criteria
    By RIZVI in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-12-2019, 08:03 AM
  2. [SOLVED] Duplicate data for multiple cells by Auto Fill / Fill Down - Dynamic Table
    By ITY in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-23-2019, 09:57 AM
  3. Fill arrays from sheet / SUMIFS / create & fill table based on multiple criteria
    By Dimitris254 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2016, 09:43 AM
  4. Auto fill worksheet cells based on certain criteria w/out leaving blank rows.
    By Txprospector in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-10-2014, 07:35 AM
  5. [SOLVED] VBA fill in cells in a new column in table based on multiple criteria from other columns
    By HRA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2013, 06:48 AM
  6. [SOLVED] Using IF to fill cells with TEXT to show staus based on multiple criteria
    By karstens in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-26-2012, 10:23 AM
  7. Auto Fill Down script
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2009, 01:07 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