+ Reply to Thread
Results 1 to 9 of 9

Groups - automatic filling of cells

  1. #1
    Registered User
    Join Date
    04-03-2020
    Location
    Livingston, Scotland
    MS-Off Ver
    2002
    Posts
    14

    Groups - automatic filling of cells

    I have created groups for say Camera Kit - and the group contains all the items that make up the kit. If the user enters data in the cell for the whole kit, I would like the same data to be added for the individual cells. Similarly if the whole group is selected, deleting information from an individual cell would delete the contents from the total.

    I'm not sure if this is possible - or if I should use VBA or macros or any other way.

    I have included an image and an example file to illustrate what trying to do.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Groups - automatic filling of cells

    I don't think grouping is the way to go here - although it might make things visually simpler.

    I'd create a table for each individual kit, and do some processing using the Worksheet_Change() event to manipulate the entries. The benefit of using a table is that rows and/or columns can be added or deleted without it being problematic for the VBA routines. Delete the extra items I've inserted, or add extra ones to try it out!

    I've attached a workbook with a bit of code I've come up with to demonstrate a possible approach. Have a look at the VBA - I've commented it a fair bit so you can see what it's doing. It looks more complicated because I've tried to make it fairly generic so it can apply to all tables on the worksheet, otherwise you'd have to edit the various ranges every time a table changed.

    Tim


    EDIT: tweaked so 1st column of the tables are disregarded - otherwise it would be impossible to edit kit items!
    Attached Files Attached Files
    Last edited by harrisonland; 04-03-2020 at 12:35 PM.
    Never stop learning!
    <--- please consider *-ing !

  3. #3
    Registered User
    Join Date
    04-03-2020
    Location
    Livingston, Scotland
    MS-Off Ver
    2002
    Posts
    14

    Re: Groups - automatic filling of cells

    Thank you, that code looks useful.

  4. #4
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Groups - automatic filling of cells

    Hope so. If you consider it done, please remember to mark the thread "SOLVED" using the thread tools at the top of the page.

    You can also show your appreciation for those that have helped by clicking the * at the left of each post if you're so inclined.

    Tim

  5. #5
    Registered User
    Join Date
    04-03-2020
    Location
    Livingston, Scotland
    MS-Off Ver
    2002
    Posts
    14

    Re: Groups - automatic filling of cells

    I'm thinking of adding a hidden column, with "1" for the group 'total' row, "0" for a group item row, and "" for an item without a group.

    Your code was a good start. I will mark it as resolved when I cam post the code.

    Thanks

  6. #6
    Registered User
    Join Date
    04-03-2020
    Location
    Livingston, Scotland
    MS-Off Ver
    2002
    Posts
    14

    Re: Groups - automatic filling of cells

    I have added the extra column and have nearly got it working.

    I can change the group 'totals' and the group items change.

    But if I delete one of the group items I want to clear the group 'total' - but then causes all the group items to be deleted.

    I have commented this line with lots of '!!!'

    I'm not sure how I stop that.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Groups - automatic filling of cells

    I'm not quite sure what the purpose of the group "total" is. Am I right in thinking that it's to distinguish between group items, and optional ones?

    Anyway, you've got conflicting interests here... in the _Change() routine, you haven't switched off Application.EneableEvents. This has the effect of changing the names successfully i.e. if you put "Tim" in E14 it populates the cells above, as intended, by triggering a new Worksheet_Change() instance for each cell.

    Leaving Application.EnableEvents = true, however, will cause a separate iteration of the Worksheet_Change() event, and it can cause a infinite loops. I think that's your problem with the line
    Please Login or Register  to view this content.
    Each change triggers another Worksheet_Change() event which results in the error you have seen. (I've not been able to replicate that, specifically, but there seem to be several anomalies causing problems.)

    Additionally, although I've not spent a lot of time analysing it, you'll notice that sometimes you get "Runtime Error 1004" - not enough memory. The reason for that is because this
    Please Login or Register  to view this content.
    never completes. If you press "Debug" on the error message and hover the cursor over the word "row" you'll see it's looped beyond 1.04 million times.

    One final observation (before I go nuts)... your line
    Please Login or Register  to view this content.
    only defines column as Integer... row is a Variant as the type isn't defined. This may cause a problem further down when you're evaluating cell values. If the cell value contains a number, but you're looking for "1", you're actually comparing a number with a string. On reflection, I wonder whether that's the issue with this looping forever:

    Please Login or Register  to view this content.
    I've re-attached a copy of my original reply, slightly modified with the extra "totals" column, and with optional items simply placed below the table for each kit. If the "Totals" column doesn't do what you want it to, you can simply exclude it from the other events for the table body by uncommenting the additional line I've put there; change it to an If ... Then statement to make it do what you want if you don't just want to exit at that point.

    You could, also, trigger additional events to automate things for the optional items if you want to.

    Tim
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    04-03-2020
    Location
    Livingston, Scotland
    MS-Off Ver
    2002
    Posts
    14

    Re: Groups - automatic filling of cells

    Tim,
    Thanks for your help, I have made the changes suggested.
    Added Application.EnableEvents=False at the start and =True at the end. I had tried this before but something else must haver been wrong.
    I didn't realise the problem with the Dim statement, I have corrected it.
    I don't think it will loop forever, as a if set up correctly a group will end with a "1".

    I should stop changes to the first 2 columns.

    I did not use you method as I have a large spreadsheet already set up (what I had provided was just a made up simple example) and it would be easier to add a few lines a code than to make each group into a separate table.

    Thanks again.

  9. #9
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Groups - automatic filling of cells

    No worries... There are often reasons we do things the way we do that aren't obvious from cut-down sample files. You're right... It won't loop forever as long as it finds a match at some point.

    Tim

+ 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. Automatic filling in cells
    By Lindsey H in forum Excel General
    Replies: 1
    Last Post: 06-13-2007, 11:45 AM
  2. [SOLVED] automatic filling in cells in excel
    By Anne Troy in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 03:05 PM
  3. automatic filling in cells in excel
    By CA user in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  4. automatic filling in cells in excel
    By CA user in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  5. [SOLVED] automatic filling in cells in excel
    By Anne Troy in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 07:05 AM
  6. [SOLVED] automatic filling in cells in excel
    By CA user in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  7. automatic filling in cells in excel
    By CA user in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  8. [SOLVED] automatic filling in cells in excel
    By CA user in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10: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