+ Reply to Thread
Results 1 to 6 of 6

How to re-write the following code line, to refer to columns by headers?

  1. #1
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    How to re-write the following code line, to refer to columns by headers?

    Hi all,

    Here is my current code line:
    Please Login or Register  to view this content.
    cl is referring to cells in the first column, so this code is supposed to join/concatenate the strings in A:C with | in between them..

    I would like to rewrite this code line, so instead of A:C it would do column A, C and E? The code refers to a table so a listobject, and if possible, it would be great to refer to the columns by their headers. A: First names, C: Last names, E: Fruits.

    Can someone help me with this please?

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: How to re-write the following code line, to refer to columns by headers?

    You can do it with an array of column numbers like this (changes highlighted):

    Please Login or Register  to view this content.
    To use column headers, you'd just create an array from the index numbers of the relevant columns.
    Rory

  3. #3
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: How to re-write the following code line, to refer to columns by headers?

    That still requires me to know the number of the columns, which I would also like to avoid if possible?

  4. #4
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: How to re-write the following code line, to refer to columns by headers?

    Also what is application.index? I have 2016 excel and I couldn't find it in the object browser.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: How to re-write the following code line, to refer to columns by headers?

    Quote Originally Posted by LIL2606 View Post
    cl is referring to cells in the first column, so this code is supposed to join/concatenate the strings in A:C with | in between them..

    I would like to rewrite this code line, so instead of A:C it would do column A, C and E? The code refers to a table so a listobject, and if possible, it would be great to refer to the columns by their headers. A: First names, C: Last names, E: Fruits.
    Try something like
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: How to re-write the following code line, to refer to columns by headers?

    Thank you for that! It does the job!

+ 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: 3
    Last Post: 08-23-2018, 09:22 AM
  2. VBA code to write from Excel to a text file AND specify line/start positions of fields
    By jsteinou99 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2017, 12:54 PM
  3. [SOLVED] dynamic vba code to delete duplicate headers, blank headers and blank columns
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2017, 02:27 PM
  4. HELP!!! Fastest code in consolidating columns with different headers
    By SBBmaster09 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2016, 09:57 PM
  5. [SOLVED] Loop through 3 columns, if 1 or more have a value, write to next line
    By pclaesen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-10-2015, 02:25 PM
  6. [SOLVED] Refer to cells in formula using column headers
    By surePac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2014, 01:25 PM
  7. [SOLVED] how to write three macro code in single line ?
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2013, 03:29 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