+ Reply to Thread
Results 1 to 18 of 18

Convert range to table without changing column width / formatting

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-19-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    208

    Re: Convert range to table without changing column width / formatting

    You realize you can record a macro of yourself creating a table from data, then looking at the code it created, right?

    To set the table style to None, replace: .TableStyle = "TableStyleLight21"

    With: .TableStyle = ""

    As for random table names, this should create a table name with a random number between 100,000 and 1,000,000 (and set the table style to None):
    Sub Macro1()
    Dim newRand As Long
    Randomize
    newRand = CLng((1000000 - 100000 + 1) * Rnd + 100000)
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range(Selection.Address), , xlYes).Name = "Table" & newRand
    With ActiveSheet.ListObjects("Table" & newRand)
        .ShowTableStyleRowStripes = False
        .ShowHeaders = True
        .TableStyle = ""
        .ShowTotals = True
    End With
    End Sub

  2. #2
    Registered User
    Join Date
    07-16-2014
    Location
    UK
    MS-Off Ver
    2016
    Posts
    90

    Re: Convert range to table without changing column width / formatting

    Quote Originally Posted by ¯\_(ツ)_/¯ View Post
    You realize you can record a macro of yourself creating a table from data, then looking at the code it created, right?
    Yes I know I can record a macro, but I don't realise I could use it as a way to find out the code of a table style.
    It's brilliant. Thanks for the tip.

    Quote Originally Posted by ¯\_(ツ)_/¯ View Post
    To set the table style to None, replace: .TableStyle = "TableStyleLight21"

    With: .TableStyle = ""

    As for random table names, this should create a table name with a random number between 100,000 and 1,000,000 (and set the table style to None):
    Sub Macro1()
    Dim newRand As Long
    Randomize
    newRand = CLng((1000000 - 100000 + 1) * Rnd + 100000)
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range(Selection.Address), , xlYes).Name = "Table" & newRand
    With ActiveSheet.ListObjects("Table" & newRand)
        .ShowTableStyleRowStripes = False
        .ShowHeaders = True
        .TableStyle = ""
        .ShowTotals = True
    End With
    End Sub
    Thank you very much.

+ 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] Macro is changing a column width and format and I don't know why.
    By Cidona in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-21-2016, 11:18 PM
  2. Convert fixed width text to table in word. It's not that easy!
    By stani87slav in forum Word Formatting & General
    Replies: 0
    Last Post: 10-04-2010, 08:03 AM
  3. Changing the column width
    By buzzing in forum Excel General
    Replies: 4
    Last Post: 03-18-2010, 06:31 AM
  4. changing column width in the middle of a spreadsheet
    By shelleyH in forum Excel General
    Replies: 2
    Last Post: 01-14-2009, 07:37 AM
  5. Changing width of a column
    By arora in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-08-2008, 04:35 AM
  6. Changing column width
    By a_dunn69 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 11-21-2006, 12:18 PM
  7. Stop column width from changing on pivot table....?
    By myk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2006, 12:45 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