+ Reply to Thread
Results 1 to 8 of 8

VBA Code to return Column header based on Criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-27-2017
    Location
    USA
    MS-Off Ver
    MS365 - 2302
    Posts
    164

    Question VBA Code to return Column header based on Criteria

    I have a spread sheet with =AND formulas that return TRUE OR FALSE based on the need.

    From Column AN to AZ are either TRUE or FALSE, I would like to see if there can be a code for Column BA to return with the name of header of the column based on the criteria.

    In column AN (header named as A) I check for "False", Column AO (header named as B) I check for "TRUE" Column AP (header named as C) I check for "False". What I check for changes based on the formula,

    Example what the code should return

    For example 1: in column AN (header: A) has only "TRUE", Column AO (Header B) has both "TRUE" and false Column AP (Header C) has only "False" . SO in Column BA (Header: What to check?) should return with header names i:e B and C.
    Reason: Header A I check for false but there is no False (So the code should return only header B and C)

    For example 2: in column AN (header: A) "TRUE", Column AO (Header B) has only "False" Column AP (Header C) has "False" . SO in Column BA (Header: What to check?) should return with header names i:e C
    The reason Column AN header should not come is because I am supposed to check for False and since there are no false it should not return the header in column BA.

    Please see the attached template I have explained with few examples highlighted in green (Table to the right Column Q/R { Is what we are supposed to filter and check for})

    https://www.mrexcel.com/forum/excel-...-criteria.html (query here but not able to provide with a template or example sets)
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,006

    Re: VBA Code to return Column header based on Criteria

    Not sure this requires VBA.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Contributor
    Join Date
    09-27-2017
    Location
    USA
    MS-Off Ver
    MS365 - 2302
    Posts
    164

    Re: VBA Code to return Column header based on Criteria

    Can this be done with a formula even thou the cells arent values?

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

    Re: VBA Code to return Column header based on Criteria

    UDF

    Use in cell like
    P3:
    =JoinIf($B$1:$N$1,B3:N3,$Q$3:$R$15,", ")

    Function JoinIf(Hdr As Range, Data As Range, Crit As Range, JoinStr As String) As String
        JoinIf = Join(Filter(Hdr.Parent.Evaluate("if(isnumber(match(" & Hdr.Address & "&char(34)&" & Data.Address & "&char(34)," & _
                 Crit.Columns(1).Address & "&" & Crit.Columns(2).Address & ",0))," & Hdr.Address & ")"), False, 0), JoinStr)
    End Function

  5. #5
    Forum Contributor
    Join Date
    09-27-2017
    Location
    USA
    MS-Off Ver
    MS365 - 2302
    Posts
    164

    Re: VBA Code to return Column header based on Criteria

    Not sure what u meant Am i supposed to put the code in a module?

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

    Re: VBA Code to return Column header based on Criteria

    See formula in col.P................
    Attached Files Attached Files

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

    Re: VBA Code to return Column header based on Criteria

    No idea about what you are talking about.

  8. #8
    Forum Contributor
    Join Date
    09-27-2017
    Location
    USA
    MS-Off Ver
    MS365 - 2302
    Posts
    164

    Re: VBA Code to return Column header based on Criteria

    Hi,

    Thank you that works just perfect.

+ 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] How to return column header based on a value from a table
    By elf607 in forum Excel General
    Replies: 12
    Last Post: 09-30-2016, 08:43 AM
  2. Replies: 6
    Last Post: 09-27-2016, 07:36 AM
  3. Replies: 3
    Last Post: 01-18-2016, 10:18 AM
  4. Return column header based on column criteria and number value
    By bwill22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-07-2014, 07:33 PM
  5. [SOLVED] Lookup based on Two Criteria to return header data
    By jsclark in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-06-2014, 01:27 PM
  6. [SOLVED] Return Value from column based on header value
    By SAsplin in forum Excel General
    Replies: 5
    Last Post: 07-16-2013, 07:46 AM
  7. [SOLVED] Trying to return a column header in a cell based on a value
    By brianfromla in forum Excel General
    Replies: 2
    Last Post: 06-26-2012, 10:37 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