+ Reply to Thread
Results 1 to 6 of 6

VBA to scan a worksheet for a specific value, and return the header and first column value

  1. #1
    Registered User
    Join Date
    02-02-2018
    Location
    Quebec city
    MS-Off Ver
    2016
    Posts
    3

    VBA to scan a worksheet for a specific value, and return the header and first column value

    Hi folks !

    I'm trying to find a way to scan an excel sheet for a value an return the header value and the first column value of the intersection in another sheet.

    Basically, I have a sheet with headers (From B5 to CW5), and the A column also contains text values (A5 to A100).

    The following range contains calculation (numbers) values (B6:CW100).

    The logic would be :

    1) Scan sheet1 (B6:CW100) for values <>0
    2) when you get a value <>0,
    - Copy the value that is <> 0 in column A of sheet2
    - Copy the header (Value in row 5 of the intersection) in column B of sheet2
    - Copy the value that is in column A of the intersection in column C of sheet2
    3) It would have to be a Paste Value to make sure to get rid of the function

    The idea is to take a matrix and turn it into a table that can be used for a pivot table...

    Ex of data in sheet1 :

    X Y Z
    ValueA 0 125 2000
    Value B 5 0
    Value C 0 12 500

    The result would be in sheet2 :

    Value Column Header Line Header
    125 Y Value A
    2000 Z Value A
    5 X Value B
    12 Y Value C
    500 Z Value C

    Can anyone help me with this ? It seems like a decent challenge I tried looking for a solution online the whole day and I could not figure it out myself ...

    Thanks a lot for your help !
    Attached Files Attached Files
    Last edited by sboivin; 02-02-2018 at 03:59 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA to scan a worksheet for a specific value, and return the header and first column v

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    02-02-2018
    Location
    Quebec city
    MS-Off Ver
    2016
    Posts
    3

    Re: VBA to scan a worksheet for a specific value, and return the header and first column v

    Done ! A very simple exemple on 2 sheets, but it's the same principle with 3 or 100 rows, and 3 or 100 columns ...

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA to scan a worksheet for a specific value, and return the header and first column v

    Try this:

    Please Login or Register  to view this content.
    and let me know

    BTW - I moved your sheet 1 sample down a row to start in B6.
    Last edited by xladept; 02-02-2018 at 05:36 PM.

  5. #5
    Registered User
    Join Date
    02-02-2018
    Location
    Quebec city
    MS-Off Ver
    2016
    Posts
    3

    Re: VBA to scan a worksheet for a specific value, and return the header and first column v

    This is just perfect !!! Thank you very much, I never would have made it without your help, this is definitely above my technical knowledge

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA to scan a worksheet for a specific value, and return the header and first column v

    You're welcome and thanks for the rep!

    BTW - Please mark this thread as solved, you can do it in Thread Tools
    Last edited by xladept; 02-14-2018 at 04:52 PM.

+ 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. Return column header when specific value is found in row.
    By houlep in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-07-2017, 11:38 PM
  2. [SOLVED] Return Row heading by Column header and specific texted cell row position
    By Amolvijay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2014, 01:39 AM
  3. Replies: 1
    Last Post: 07-11-2014, 02:36 PM
  4. [SOLVED] Find specific value in table and return header row and header column value
    By nelwan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2013, 01:35 AM
  5. Scan a row for text; return row and column header info
    By Kronote in forum Excel General
    Replies: 5
    Last Post: 06-02-2013, 06:43 PM
  6. Replies: 6
    Last Post: 07-26-2012, 06:34 PM
  7. scan data, find max value of column, return single record on other worksheet
    By virtualnoob in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-26-2012, 11:26 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