+ Reply to Thread
Results 1 to 13 of 13

Resize a table or........?

Hybrid View

Frigide Resize a table or........? 11-24-2021, 03:29 PM
mehmetcik Re: Resize a table or........? 11-24-2021, 04:32 PM
Frigide Re: Resize a table or........? 11-24-2021, 05:20 PM
Frigide Re: Resize a table or........? 11-24-2021, 06:04 PM
mehmetcik Re: Resize a table or........? 11-24-2021, 06:47 PM
Frigide Re: Resize a table or........? 11-24-2021, 06:54 PM
mehmetcik Re: Resize a table or........? 11-24-2021, 07:33 PM
Frigide Re: Resize a table or........? 11-25-2021, 02:57 AM
Frigide Re: Resize a table or........? 11-25-2021, 03:33 AM
mehmetcik Re: Resize a table or........? 11-25-2021, 05:11 AM
Frigide Re: Resize a table or........? 11-25-2021, 06:10 AM
mehmetcik Re: Resize a table or........? 11-25-2021, 06:28 AM
Frigide Re: Resize a table or........? 11-25-2021, 06:47 AM
  1. #1
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Resize a table or........?

    With this code i copy 8 lines to a table. The table is +/- 35 columns wide.

    Dim y As Integer
        For y = 0 To 7
        nRow = shP.Range("B" & shP.Rows.Count).End(xlUp).Offset(1).Row
            shP.Cells(nRow, 2) = shJ.Cells(7, 13 + y).Value
            shP.Cells(nRow, 3) = 41
            shJ.Range("$D$9").AutoFilter Field:=1, Criteria1:="=40", _
            Operator:=xlOr, Criteria2:="=41"
            shJ.Range(Cells(10, 13 + y), Cells(shJ.Cells(Rows.Count, 3).End(xlUp).Row, 13 + y)).Copy
            shP.Cells(nRow, 4).PasteSpecial Paste:=xlPasteValues, Transpose:=True
        
    
            shP.Cells(nRow + 1, 2) = shJ.Cells(7, 13 + y).Value
            shP.Cells(nRow + 1, 3) = 42
            shJ.Range("$D$9").AutoFilter Field:=1, Criteria1:="=40", _
            Operator:=xlOr, Criteria2:="=42"
            shJ.Range(Cells(11, 13 + y), Cells(shJ.Cells(Rows.Count, 3).End(xlUp).Row, 13 + y)).Copy
            shP.Cells(nRow + 1, 4).PasteSpecial Paste:=xlPasteValues, Transpose:=True
        Next y
    But because there are cell with a Matrixformule witch more then one cell the code gives a error.

    To prefend to copy in a table and get this error i stop the table from expending with this.
    Application.AutoCorrect.AutoExpandListRange = False
    But when i use
    Application.AutoCorrect.AutoExpandListRange = True
    the table don't expand on it own.

    How to expand a table or copy matrix formulas with more then one cell to a table?

    The table in in sheet "PKB" and the table is called "PKB".

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Resize a table or........?

    All you need to do to expand a table is to insert new data in a new row or column imediately next to the column.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: Resize a table or........?

    Yep that is what i want.
    I thought i had a solution.
        With Worksheets("PKB").ListObjects("PKB")
            .Resize .Range(1, 1).CurrentRegion
        End With
    But somehow ".Resize .Range(1, 1).CurrentRegion" gives a error when the sheet is protected. Even when UserInterFaceOnly:=True

    So i still have no answer to the problem.

  4. #4
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: Resize a table or........?

    This is the sheet with the tabel. The question is how to make the last 16 rows part of the table with a VBA code when the sheet is protected.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Resize a table or........?

    
    'This line selects the table.  can be deleted.
        Range("PKB[[#Headers],[Datum / tijd]]").Select
    
    'This line resizes the table. 
        ActiveSheet.ListObjects("PKB").Resize Range("$B$5:$CO$133")

  6. #6
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: Resize a table or........?

    It is a growing list. Every day 48 more lines!

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Resize a table or........?

    Ahhh.

    I have added a sheet of useful code for you.

    Eg. This line returns the last used row in column 1.
    LR = Cells(rows.count,2).End(xlUp).Row


    So your Macro becomes

    'Find the last used row in column 2
    LR = Cells(rows.count,1).End(xlUp).Row
    
    'This line selects the table.  can be deleted.
        Range("PKB[[#Headers],[Datum / tijd]]").Select
    
    'This line resizes the table. 
        ActiveSheet.ListObjects("PKB").Resize Range("$B$5:$CO$" & LR)
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: Resize a table or........?

    Changes
    LR = Cells(rows.count,1).End(xlUp).Row
    in

    LR = Cells(rows.count,2).End(xlUp).Row
    and it is working like a charm!

    Tanks

  9. #9
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: Resize a table or........?

    Maybe in the near future someone adds a column. So i like to count columns to.
    Where do i put de LC?

    Set ShI = Sheets("PKB")
    
    LR = ShI.Cells(Rows.Count, 2).End(xlUp).Row
    LC = ShI.Cells(2, Columns.Count).End(xlToLeft).Column
    ShI.ListObjects("PKB").Resize Range("$B$5" & LC & LR)

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Resize a table or........?

    LR = Cells(rows.count,2).End(xlUp).Row

    LC = ShI.Cells(5, Columns.Count).End(xlToLeft).Column

    'So:
    'Last Cell = cells(LR,LC)

    'This line resizes the table.
    ActiveSheet.ListObjects("PKB").Resize Range("$B$5",cells(LR,LC))




    Or Last Cell = Selection.SpecialCells(xlCellTypeLastCell).Address

    'So:
    'This line resizes the table.
    ActiveSheet.ListObjects("PKB").Resize Range("$B$5:" & Selection.SpecialCells(xlCellTypeLastCell).Address)
    Last edited by mehmetcik; 11-25-2021 at 05:21 AM.

  11. #11
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: Resize a table or........?

    This in not working. I don't see why. Never got stuk on something so small in VBA before.

    Sub test()
    Set ShP = Sheets("PKB")
    LR = ShP.Cells(Rows.Count, 2).End(xlUp).Row
    LC = ShP.Cells(5, Columns.Count).End(xlToLeft).Column
    ShP.ListObjects("PKB").Resize Range("$B$5", Cells(LR, LC))
    
    End Sub

  12. #12
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Resize a table or........?

    That code seems to work.
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: Resize a table or........?

    Not when the sheet is protected? Unlock the sheet is not ideal.

+ 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. Replies: 1
    Last Post: 09-19-2021, 08:29 PM
  2. Replies: 5
    Last Post: 06-12-2020, 01:55 PM
  3. [SOLVED] Resize table to fit one or two pages
    By stojko89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2018, 03:26 PM
  4. [SOLVED] Resize a table to fit my pages
    By jomili in forum Word Formatting & General
    Replies: 14
    Last Post: 07-31-2017, 06:34 PM
  5. Macro to Resize a Table
    By brent_milne in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2015, 11:37 AM
  6. UserInterFaceOnly and resize of table
    By wibble98 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2014, 10:08 AM
  7. [SOLVED] Resize table to same row count as a piovt table
    By djon5020 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2014, 01:43 AM

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