Results 1 to 3 of 3

Thread: excel vba resize how can i control the resize and keep specific columns
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jan 2019
    Posts
    111
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default excel vba resize how can i control the resize and keep specific columns

    So when I import data to my table it often has an erradict and unpredictable amount of columns which is fine except when I want to resize I would like to keep the first 8 columns of the table and delete any of the rest.

    This works great below except my coulumns seem to keep the last 8 of the columns instead of the first 8.

    Any guidance is appreciated.

    oh and DCRPT is the "Named Table" I am using.

    Code:
    With DCRPT.DataBodyRange
        If .Rows.Count > 1 Then
          .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count - 8).Rows.Delete
        End If
      End With

  2. #2
    Board Regular Akuini's Avatar
    Join Date
    Feb 2016
    Location
    Indonesia
    Posts
    2,032
    Post Thanks / Like
    Mentioned
    33 Post(s)
    Tagged
    4 Thread(s)

    Default Re: excel vba resize how can i control the resize and keep specific columns

    I would like to keep the first 8 columns of the table and delete any of the rest.
    Try this:
    If 'Table1' has more than 8 column then it will delete the 9th to the last column.

    Code:
    With ActiveSheet.ListObjects("Table1")
        n = .Range.Columns.count
            If n > 8 Then .ListColumns(9).Range.Resize(, n - 8).Delete
    End With
    Last edited by Akuini; Aug 25th, 2019 at 12:04 AM.

  3. #3
    Board Regular
    Join Date
    Jan 2019
    Posts
    111
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: excel vba resize how can i control the resize and keep specific columns

    Perfect addition, I appreciate it.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •