+ Reply to Thread
Results 1 to 5 of 5

Convert through Macro an Excel Table to a Range

Hybrid View

  1. #1
    Registered User
    Join Date
    03-14-2016
    Location
    iNDIA
    MS-Off Ver
    2007
    Posts
    3

    Convert through Macro an Excel Table to a Range

    I have a small issue here.
    1) I am sending an excel sheet to my users . This sheet has a macro. In this sheet my users will paste varying rows of data values GL Accountwise / Buisness Areawise / Currencywise.

    2) Then they will run the macro ( I recorded the macro ) which converts the data to an excel official table ,converts the data into a summarized format by creating a pivot table in the sheet itself through the macro . If the data is not converted to a table the macro does not work.

    This is all working fine. But the issue is that if users re-run the macro a second time without converting the table to a range ,the macro gives an error “A table cannot overlap another table”. I need to reset the base data from a excel table to a range from the macro itself .

    I tried to record a macro which resets the table to range from the menu, but the macro seems to record nothing.


    Could you help?

    Thanks.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Convert through Macro an Excel Table to a Range

    Hi, I suugest to do the following.
    It's simple and will show you what to do.

    Start recording macro #1:
    select the table and convert to range
    Stop the recording

    Start recording macro #2:
    Select the range required
    Convert this to Table
    Stop the recording

    All you need to do is enter a check if the table exists and then run the macro #1 to set to range

    The second one can only be run if the Table dose not exists.

    I hope this helps to give you an idea.

    BTW if peroble add data to an existing table it will automatically adapt and resieze.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    03-14-2016
    Location
    iNDIA
    MS-Off Ver
    2007
    Posts
    3

    Re: Convert through Macro an Excel Table to a Range

    OK. Thank you so much Keebellah.

    I will try and get back to you.

    Thanks Once again.

  4. #4
    Registered User
    Join Date
    03-14-2016
    Location
    iNDIA
    MS-Off Ver
    2007
    Posts
    3

    Re: Convert through Macro an Excel Table to a Range

    Hi Keebellah

    As I had mentioned in my first post itself, When you record a macro : Select the table and either from the menu or by right clicking you convert the table to a range and stop the macro, the macro seems to record nothing. The macro does not record the steps. Sorry to trouble once again.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Convert through Macro an Excel Table to a Range

    You mentioned that but what I mentioned was that you need to add a test to see if the table is already present to avoid the errors.

    Create a small table in a new blank workbook

    Range B4 - F4 will be the header
    B5 - F 6 is the date, two rows


    Public Sub rng2Table()
    Dim table   As ListObject
    If Tbl2rng = True Then Exit Sub
    Range("B4:F6").Select
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$B$4:$F$6"), , xlYes).Name = _
        "TestTable"
    Range("B1").Select
    End Sub
    
    Public Function Tbl2rng() As Boolean
    Dim table   As ListObject
    On Error GoTo noTable
    Set table = ActiveSheet.ListObjects.Item("TestTable")
    Tbl2rng = True
    noTable:
    Err.Clear
    On Error GoTo 0
    Range("B1").Select
    End Function
    If you place the above two macros in a blank workbook and run them:


    rng2Table will create a table if does not already exists for the selected range

    tbl2rng will convert the table to range if the table is present

    The table name will be 'TestTable"

    This is what I meant

+ 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: 4
    Last Post: 11-29-2015, 07:20 AM
  2. Convert Word Table Macro to excel macro
    By vel90 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2015, 01:20 PM
  3. Macro to convert date range to individual line items (i.e. rows) in excel
    By violetmind in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-11-2014, 09:53 PM
  4. VBA how to convert a range to a table in excel 2010
    By LindaB1016 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-27-2014, 11:26 PM
  5. [SOLVED] Macro to Convert Selected Range to Table
    By AHFoddeR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2013, 08:39 PM
  6. Replies: 0
    Last Post: 01-27-2012, 10:55 AM
  7. Macro to convert mailing address list into excel table
    By ravikiran in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-04-2010, 07:30 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