+ Reply to Thread
Results 1 to 3 of 3

vba excel match replace column header using criteria

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    vba excel match replace column header using criteria

    I have a problem where I'm not sure where to begin. I know that using temp sh is probably the best way to start. I have 110 columns that a fellow programmer misnamed the header attributes. Since this is an external data source (*.csv), I have no control to rename the attributes correctly. What I want to do is loop through the header row and rename each attribute correctly. For example c1 (incorrect) would be renamed to HC1 (correct)...etc.

    I know this would be fairly simple since I would just match ws1.Cell(1,1) with ws2.Cell(1,i) and replace ws1.Cell(1,1) with Found ws2.Cell(1,i).Offset(0,1)...something like:
    Please Login or Register  to view this content.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: vba excel match replace column header using criteria

    If you have a list of the incorrect headers in column A and the corresponding correct ones in column B, same row of sheet 1 then the headers in sheet 2 can be corrected like this:
    Please Login or Register  to view this content.
    If there are no incorrect headers on the sheet it simply ignores everything and ends the procedure. In other words it will only correct somethig if it finds a match.
    Last edited by JLGWhiz; 04-25-2019 at 07:04 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel match replace column header using criteria

    Very nice. Replace! I figured it would probably be something that simple. Thanks JLGWhiz.

+ 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: 5
    Last Post: 03-19-2019, 11:41 AM
  2. Match Criteria in Range & Extract Column Header
    By sp0ck1 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-26-2018, 06:27 AM
  3. [SOLVED] looping through columns to find a value then replace said value with column header
    By Sybille in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2018, 10:38 AM
  4. Helped needed to index match row header, column header, and sheet
    By vw103604 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-15-2016, 12:37 PM
  5. Replies: 3
    Last Post: 01-18-2016, 10:18 AM
  6. Replies: 1
    Last Post: 10-05-2013, 03:35 PM
  7. Replies: 3
    Last Post: 04-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