+ Reply to Thread
Results 1 to 17 of 17

Set Table Size?

  1. #1
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Set Table Size?

    Hello all,

    Is there a way to set a table size so that even if you add a few rows the table will adjust the cell height and stay the same size? I think you can do this with charts simply by formatting the size but I don't know of a way to do that with tables.

    I ask this because I developed a SharePoint site with a dashboard using some excel charts and tables. Either because of my limited SP experience or the fact that I am unable to use SP Designer, I couldn't find a way to adjust the size of the charts and tables within the site. Because of this I had to adjust the size of the charts and tables in Excel. Well, right now it looks perfect but my internship is ending soon and I would like it if when the data is altered later that the table sizes don't change. Right now the tables have a fair amount of space and I think they could have about 5 more rows added without needing to expand anything. I don't think that these tables will have any more than 5 rows added in the future so I would really like the tables to remain the same size.

    Anyone have any ideas?

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Set Table Size?

    Try event code like this - copy the code, right-click the sheet tab, select "View code", and paste in the window that appears.

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Hi Bernie,

    Thanks for the input but it didn't seem to do anything. The table didn't change size (which is good) but when I changed 240 to 480 to see if the code was working, nothing changed. I don't really know anything about macros so I'm not sure what the problem is.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Set Table Size?

    Well, the code is only applied when the row count of Table1 increases above 20. So grab the table size handle and drag down, and the once you get more than 20 rows, the rows should change height. If you want to see it in action with all row counts, just use this version:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Set Table Size?

    Well, the code is only applied when the row count of Table1 increases above 20. So grab the table size handle and drag down, and the once you get more than 20 rows, the rows should change height. If you want to see it in action with all row counts, just use this version:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Thanks Bernie!

    The original code does the trick. I just needed to adjust the amount of rows and 240 is actually the perfect height. How crazy is that? lol

    I appreciate the help
    Last edited by SomeDude0nline; 08-12-2014 at 11:59 AM.

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Set Table Size?

    240 is always the answer - you just need to adjust the units to suit

  8. #8
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Hmm, how do you adjust the units to suit? I would like for the bottom row (totals row) to be a specific size. Is that possible with this code?

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Set Table Size?

    Sorry, that was an old engineering joke. Say, for example, the real answer is 24 inches. Then you give the answer as 240 but with the units tenths-of-an-inch. Any number can be expressed as 240 if the units are adjusted appropriately.... a related engineering standby is the "<insert name of the smartest kid in the class here> constant", which is how much you need to add to, subtract from, mutliply, or divide your answer by to get the correct answer.

    Anyway, to change the bottom row to a specific height, use code like this

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 08-12-2014 at 01:15 PM.

  10. #10
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Thanks again,

    I'm sorry to keep dragging this out but I thought the code would make more sense to me so I could manipulate it a little myself. But that isn't the case lol. What is iTR? Is it just a label you made up to signify "Integer Totals Row"? How does the code know that you're applying this to the last row in the table? Do I need to label the bottom row as "Totals"? The last line before End Sub looks like you're applying the Totals Row height to the last row but I can't see how you're referencing the last row specifically.

    The reason I wanted to manipulate it myself was because I realized that I want to adjust the top row as well. However it is that you're applying the height to the bottom row, I imagine I need to do that for the top row as well then simply change the count to "2" instead of "1".

    I think what's really got me confused is the line below. I'm reading it as ListObjects "Table 1" the range of the table to apply the command to is, ListObjects "Table 1" the range is all cells. Maybe the problem is I don't know what "count" is. It seems like it is a command to count (der... lol) but I don't see how that applies here.
    Please Login or Register  to view this content.
    Again, I'm sorry for dragging this out. You've already been a big help, I just end up wanting to make further tweaks after I see results sometimes and understanding how the code works will help me do that.
    Last edited by SomeDude0nline; 08-12-2014 at 01:57 PM.

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Set Table Size?

    Let's break this down:

    ListObjects("Table1").Range(ListObjects("Table1").Range.Cells.Count).EntireRow.RowHeight = iTR

    ListObjects("Table1") is the table
    ListObjects("Table1").Range are the cells of the table
    ListObjects("Table1").Range.Cells.Count is how many cells there are in the table
    ListObjects("Table1").Range(ListObjects("Table1").Range.Cells.Count) is the bottom right (last cell) of the table

    EntireRow means the entire row of the range
    RowHeight is the row height for a range that is a row

    and iTR is the height we want for that row.

    We can use Range(1) since we know the headers are always in the top row, and cell 1 is the top left cell of the table.

    So, all together, this

    ListObjects("Table1").Range(ListObjects("Table1").Range.Cells.Count).EntireRow.RowHeight = iTR

    can be read as "In Table1, set the last cell's entire row height to the value stored in the variable iTR"

    We have to set the entire row's height since height is not a property of a table object. You don't need to label that row, as long as your table is set up to have totals as the last row.

    So, for the first row:

    Dim iHR As Integer 'integer header row height
    iHR = 30
    ListObjects("Table1").Range(1).EntireRow.RowHeight = iHR

    (Note that you need to adjust the height that is being shared by the other rows: 240-iTR-iHR, and subtract 2 instead of 1 in the divisor

    We can use Range(1) because the headers are always in the top row, and cell 1 is the top left cell of the table.

    But - if you ever want to write a macro that is not event code, you need to fully qualify the ListObject: event code applies to objects on that sheet, so qualification is not needed:

    Woksheets("Sheet Name").ListObjects("Table1").Range(1).EntireRow.RowHeight = iHR
    Last edited by Bernie Deitrick; 08-12-2014 at 03:12 PM.

  12. #12
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Bernie,

    Thank you so much for the detailed explanation. I never would have guessed that this "ListObjects("Table1").Range(ListObjects("Table1").Range.Cells.Count)" is referring to the bottom right cell.

    Have a great day!

  13. #13
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Hello Again,

    If I'm annoying you please let me know lol. Is there a way to incorporate this
    Please Login or Register  to view this content.
    into the code below? I gave it a shot and tried to also subtract "Selection" from 240 but as you probably know, that produces a type mismatch. What I'm trying to do now is to have one of the rows auto-fit because the cell wraps. Is there someway to include this Selection as an exception or would it require a much more complicated Macro?

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Hello Again,

    If I'm annoying you please let me know lol. Is there a way to incorporate this
    Please Login or Register  to view this content.
    into the code below? I gave it a shot and tried to also subtract "Selection" from 240 but as you probably know, that produces a type mismatch. What I'm trying to do now is to have one of the rows auto-fit because the cell wraps. Is there someway to include this Selection as an exception or would it require a much more complicated Macro?

    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Set Table Size?

    Easy....

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Cool! Thanks Again

  17. #17
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: Set Table Size?

    Cool! Thanks 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. Macro to "Pull Down or Up" a Table based on Pivot Table Size
    By rmmohan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2013, 09:16 AM
  2. macro to put zero's in table array - table array will vary in size each time
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2012, 06:12 AM
  3. Changing size of table
    By Lynild in forum Excel General
    Replies: 0
    Last Post: 06-06-2010, 05:13 PM
  4. Auto size a pivot table to a page size
    By *.* in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-23-2006, 12:09 AM
  5. How to define table size
    By carlos10 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-15-2006, 01:35 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