+ Reply to Thread
Results 1 to 6 of 6

Similar headers exist but not able to remove/rename and keep correct header

  1. #1
    Registered User
    Join Date
    04-28-2016
    Location
    San Diego, CA
    MS-Off Ver
    8
    Posts
    3

    Question Similar headers exist but not able to remove/rename and keep correct header

    I am exporting information from different versions of a schematic program in tab delimited text that will be imported back into the schematic. Over the years/versions some of the header information has changed slightly. I need to search for the preferred header, if it exists I want to keep it (do nothing) but remove the other similar headers. If it doesn't exist, I would like to search for the similar name and rename it if it exists.

    I have no code that makes sense enough to post.

    Header example: PL Position vs. PL_Position
    The underscore header is the preferred header.
    Last edited by PC2016; 04-28-2016 at 01:34 PM. Reason: Add additional information/clarification

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Similar headers exist but not able to remove/rename and keep correct header

    without actual data or structure to go by

    can you not just substitute " " with "_"
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-28-2016
    Location
    San Diego, CA
    MS-Off Ver
    8
    Posts
    3

    Re: Similar headers exist but not able to remove/rename and keep correct header

    I could do that but in some cases I will have both properties existing in the same export file. I would like to test for the duplicate and remove one if there are two, or rename if the one exists but is not the underscored version.

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Similar headers exist but not able to remove/rename and keep correct header

    can you post some sample data so i can see what your dealing with

  5. #5
    Registered User
    Join Date
    04-28-2016
    Location
    San Diego, CA
    MS-Off Ver
    8
    Posts
    3

    Re: Similar headers exist but not able to remove/rename and keep correct header

    Part of the issue is that sometimes the property will not exist at all. I need to search for three possibilities: does not exist (then add it), exists but not named correctly (BAAN Position) and rename (BAAN_Position), exists and correct - continue to next sub. I have been trying to figure out the ElseIf but not sure if that is the best way. This is the partial working code but still need the if not there part.

    CODE
    Sub M4A_Rename_BAANPosition()
    '
    ' Find the BAAN Position column and Rename
    '
    Dim BAAN_Position As Boolean
    BAAN_Position = True
    '
    Sheets("BAAN_BOM_From OrCAD").Select
    If BAAN_Position = False Then
    Range("BAAN Position").Select
    Cells.Replace What:="BAAN Position", Replacement:="BAAN_Position", LookAt _
    :=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    Else
    Call M4B_Find_BAAN_Position_Add_formula
    End If

    End Sub

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Similar headers exist but not able to remove/rename and keep correct header

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    what exactly is BAAN_Position meant to be ? a named range?

    ps you have set BAAN_Position to True so it will always go to Else?

+ 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] Excel VBA to rename Column headers with same name/Value
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-26-2015, 08:05 PM
  2. Replies: 0
    Last Post: 09-11-2013, 09:54 AM
  3. Count Number of occurences Across Columns based on Similar Column Headers
    By vidyuthrajesh in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-27-2013, 06:42 PM
  4. Excel 2007 : Add cells with a similar header
    By NovaNardis in forum Excel General
    Replies: 0
    Last Post: 09-09-2011, 09:45 AM
  5. Macro to automatically rename row headers
    By Zyphon in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-09-2008, 04:41 AM
  6. Combine similar products and put into correct columns
    By treva26 in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 07-02-2007, 08:00 PM
  7. IsPossible to rename header ABCD row?
    By rtf500 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 01-08-2006, 08:24 AM

Tags for this Thread

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