+ Reply to Thread
Results 1 to 9 of 9

Macro Help - Newb here... Creating Table

  1. #1
    Registered User
    Join Date
    04-29-2014
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro Help - Newb here... Creating Table

    Hey All,
    So i'm definitely not smart with this stuff (which is why I'm coming to you all!)

    Here's what we're trying to do. We have a single worksheet and need to keep it on one sheet. The top "table" will be edited by the user. They will have the ability to insert rows and the data as necessary. Below this user-defined table we need two tables that separate the data that was collected.

    I'll try to explain this as best as possible and have attached the document as well.

    The table that people have the ability to edit/add to contains a model number, description of the item, total quantity of item sent, and the total quantity of that item they would like to return. The macro will need to separate the items by the quantity of items staying vs. the items being returned. The return table should just pull values from the "Return Qty" column (Column E). The Items Staying table will need to do a simple subtraction of Column D minus Column E (Qty minus Return Qty).

    I have searched many forums and spent too much time on the interwebs and I'm getting frustrated. Was hoping to find a similar code that I could manipulate to my needs, but again, I suck at this. My big hang up is the fact that people will have the ability to ADD rows to the user defined table. I was going to do some simple formula (if/then statements) to just copy data down, but that ability to add tables makes me feel like the macro is needed.

    Any of you able to help out??
    Last edited by vipvanilla; 05-02-2014 at 12:36 PM. Reason: Problem solved!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro Help - Newb here... Creating Table

    Hello vipvanilla,

    Welcome to the Forum!

    This can be done using VBA. I need a little more information before I start coding a solution for you.

    Your top table has 54 rows. Your two bottom tables have only 20 each. This means the maximum entries that could recorded to the bottom tables would be forty.

    The top table should start with forty rows. As rows are added to the top table, the macro would add a now to each bottom table. Would this work for you?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    04-29-2014
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro Help - Newb here... Creating Table

    Hi Leith,

    First, thank you for the quick reply! (Sorry I wasn't faster to reply back). I really appreciate your willingness to help with this.

    So your question is part of the problem I was coming across. For sake of understanding, let's call the top table that currently has 52 rows "Table 1." Table 1 cannot be a set length, rather needs to be editable by the user. There may be times that Table 1 has 10 rows of information, and other times when Table 1 may have 100 lines of information.

    With that as the foundation, my thought (i.e., hope and prayer) was that I could have a button near that top of Table 1. A "Sort Data" button that would create the other two tables as needed (Let's call them "Table Staying" and "Table Returning"). I simply added the 20 rows in Tables Staying and Returning to give a visual, but was not set on the number of rows as I had hoped the VBA would determine that number based on the data in Table 1. My thought was the "Insert > Table" option in Excel might be "code-able" based off of Table 1.

    What do you think? Is that possible?

  4. #4
    Registered User
    Join Date
    04-29-2014
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro Help - Newb here... Creating Table

    Bump this to the top

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro Help - Newb here... Creating Table

    Hello vipvanilla,

    The macro below has been added to the attached workbook. A button has been added to the "Addendum" worksheet. A new worksheet has also been added named "Tables". This holds the two tables that will be copied below the main table.

    Here is the code for the macro "AddTables" in Module2.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-29-2014
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro Help - Newb here... Creating Table

    THIS.IS.AMAZING!!!

    Thank you SOOOO much!!!

    I found that if the last row had data entered OR if it was deleted, the entire macro would not run. I'm not sure why that is. I looked through the VBA but couldn't tell why that would happen. So I just ended up hiding that row and everything works magnificently now.

    Thanks again!

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro Help - Newb here... Creating Table

    Hello vipvanilla,

    You're welcome. Good job on the fix. It's very clever.

  8. #8
    Registered User
    Join Date
    04-29-2014
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro Help - Newb here... Creating Table

    Leith,

    So I ran my first report and now the team would like to add one more function. I got in and tried myself, but failed miserably. :-/

    If the Qty is zero in either the Staying or Returning tables, they would like that excluded. I was thinking I could do a basic code in your copy commands, but am struggling with getting it to work.

    ' Add Equipment Remaining at Facility Table.
    r = EquipList.Rows.Count + EquipList.Row + 2
    TableWks.Range("A1").CurrentRegion.Copy Wks.Cells(r, "A")

    ' Add Equipment Returned to facility Table.
    r = r + TableWks.Range("F1").CurrentRegion.Rows.Count + 2
    TableWks.Range("F1").CurrentRegion.Copy Wks.Cells(r, "A")

  9. #9
    Registered User
    Join Date
    04-29-2014
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro Help - Newb here... Creating Table

    So I found out how to delete rows. This is the code I ended up using right before the End Sub
    Please Login or Register  to view this content.
    not sure i understand everything in it, but it appears to be working fine!

+ 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] Creating Macro Table
    By Julian86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2013, 09:10 AM
  2. [SOLVED] Creating new table with macro
    By damaple in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-01-2013, 05:14 AM
  3. Newb needs help on how to populate a table
    By Mr Nat in forum Excel General
    Replies: 1
    Last Post: 07-09-2013, 09:20 PM
  4. Newb VBA developper needs Macro help with dates
    By baggio7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-30-2010, 01:18 AM
  5. Newb needs macro help.
    By S3NTYN3L in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-06-2006, 09:16 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