+ Reply to Thread
Results 1 to 7 of 7

Macro to Rename One of Two Identical Column Names

  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    Neosho, MO
    MS-Off Ver
    Excel 2010
    Posts
    4

    Macro to Rename One of Two Identical Column Names

    I have a data extract that is in the format of an Excel workbook. The file is exported from a web interface by a person. I am importing this extract into SQL Server via SSIS. The problem is that there are two columns on the worksheet that have the same name. I need a way to find the the second instance of the column name and tack a "1" or something to the end of the field name. I would also like to programatically change the tab name.

    I was thinking of a template file that the user could paste the exported data into, then run a macro to rename that second field and the tab, then save the file as normal.

    Any ideas?

    Thanks

    PK

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to Rename One of Two Identical Column Names

    Hi,

    try this, works with an unspecified amount of duplicate column headers, the first duplicate remains while each following is renamed by adding "_1" and so on
    I assumed the headers to be in row 1:
    Please Login or Register  to view this content.
    Regards
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    04-23-2013
    Location
    Neosho, MO
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to Rename One of Two Identical Column Names

    This appears to work quite nicely.

    Now, is there a way to rename the tab within this same macro?

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to Rename One of Two Identical Column Names

    Yes it is,

    put
    Please Login or Register  to view this content.
    Regards

  5. #5
    Registered User
    Join Date
    04-23-2013
    Location
    Neosho, MO
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to Rename One of Two Identical Column Names

    Thank you! I almost have the functionality that i need. I figured out how to "save as" through the macro, but the file that i am trying to work with is actually XML data with an XLS extension. When i use .SaveAs Filename:="filename.xls" it still just saves it with an XLS extension. Do you know how to code a "Save as type:" to force it to save as Excel formatted XLS?

  6. #6
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to Rename One of Two Identical Column Names

    Hi,

    please find a detailed documentation of the SaveAs function here: http://msdn.microsoft.com/en-us/libr.../ff841185.aspx
    and the values for the "FileFormat" parameter here: http://msdn.microsoft.com/en-us/libr.../ff198017.aspx

    Actually xls is an excel format extension, if you want to save as xml use:
    Please Login or Register  to view this content.
    Regards

  7. #7
    Registered User
    Join Date
    04-23-2013
    Location
    Neosho, MO
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to Rename One of Two Identical Column Names

    Yep. XLS is the file format that i need it to save as. I think i found my answer. Thank you so much for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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