+ Reply to Thread
Results 1 to 4 of 4

How to reference a table named in an input box?

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    How to reference a table named in an input box?

    Hello All,

    I am creating a macro that will create a table from a selection and then format it appropriately. I use an input box to name the table, but then I'm not sure how to refer to this table in the VBA code since it's name will be different each time the macro is used. Here is a portion of the code so far:

    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$L$1:$N$3"), , xlYes).Name = _
            InputBox("What is the name of the table?")
        Range("Table9[#All]").Select
    I'm not sure what to use to replace "Table9" so that whatever name was just keyed in by the user is referred to.

    Any help would be greatly appreciated. Thanks!

    Joe

  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,259

    Re: How to reference a table named in an input box?

    Hello JoeSkittles,

    If you can post a copy of your workbook, it will greatly help in answering your question.

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

    File Manger Picture
    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
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: How to reference a table named in an input box?

    Example.xlsm

    Here ia workbook if that will help. Thanks in advance!

    Joe

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

    Re: How to reference a table named in an input box?

    Hello JoeSkittles,

    Thanks for the workbook. I could not have made this revision with out it. Here is the revised code...
    Sub Macro6()
    '
    ' Macro6 Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+T
    '
        Dim oTable As ListObject
        
        ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes).Name = _
            InputBox("What is the name of the table?")
            
        Set oTable = ActiveSheet.ListObjects(ActiveSheet.ListObjects.Count)
        oTable.TableStyle = "TableStyleMedium16"
        
        With oTable.HeaderRowRange
            .Font.Name = "Calibri"
            .Font.Size = 9
            .Font.Strikethrough = False
            .Font.Superscript = False
            .Font.Subscript = False
            .Font.OutlineFont = False
            .Font.Shadow = False
            .Font.Underline = xlUnderlineStyleNone
            .Font.ThemeColor = xlThemeColorLight1
            .Font.TintAndShade = 0
            .Font.ThemeFont = xlThemeFontMinor
        End With
        
        With oTable.HeaderRowRange
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        
        With oTable.DataBodyRange
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        
        Range("L2").Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlDown)).Select
        
        With Selection.Font
            .Color = -65536
            .TintAndShade = 0
        End With
        
        With Selection.Font
            .Name = "Calibri"
            .Size = 8
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .Color = -65536
            .TintAndShade = 0
            .ThemeFont = xlThemeFontMinor
        End With
        
    End Sub

+ 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. Absolute reference on named table
    By one11 in forum Excel General
    Replies: 2
    Last Post: 10-18-2011, 02:15 PM
  2. [SOLVED] Input cell reference is not valid (One Variable Data Table)
    By Max in forum Excel Formulas & Functions
    Replies: 27
    Last Post: 09-06-2005, 08:05 AM
  3. Input cell reference is not valid (One Variable Data Table)
    By Dottore in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 AM
  4. Input cell reference is not valid (One Variable Data Table)
    By Dottore in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. Input cell reference is not valid (One Variable Data Table)
    By Dottore in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-01-2005, 11:05 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