+ Reply to Thread
Results 1 to 7 of 7

Find first occurrence across multiple columns

  1. #1
    Registered User
    Join Date
    07-16-2019
    Location
    New Zealand
    MS-Off Ver
    365
    Posts
    44

    Find first occurrence across multiple columns

    Hi Excel Forum,

    I want to create a macro which identifies the first occurrence of a string and inputs "y" to an adjacent cell. I am hoping to accomplish something like the following:

    Please Login or Register  to view this content.
    Any help resolving this issue is appreciated.

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Find first occurrence across multiple columns

    It not clear for me with "first occurence within same range "
    If you want to put "y" where 1st unblank cell found in COLUMN:
    PHP Code: 
    Sub firstoccurence()
    For 
    1 To 4
        
    For 1 To 100
            
    If Cells(rc) <> "" Then
                Cells
    (rc).Offset(04) = "y"
                
    Exit For
            
    End If
        
    Next r
    Next c
    End Sub 
    Or 1st unblank cell found in ROW:
    PHP Code: 
    Sub firstoccurence2()
    For 
    1 To 100
        
    For 1 To 4
            
    If Cells(rc) <> "" Then
                Cells
    (rc).Offset(04) = "y"
                
    Exit For
            
    End If
        
    Next c
    Next r
    End Sub 
    Quang PT

  3. #3
    Registered User
    Join Date
    07-16-2019
    Location
    New Zealand
    MS-Off Ver
    365
    Posts
    44

    Re: Find first occurrence across multiple columns

    Hi bebo021999,

    I'm sorry my first post wasn't clear. I would like the macro to search for the value Cells(r,c) across the range A1:D100 and for only the first match, output "y" the cell Cells(r,c).Offset(0,4).

    I hope this makes more sense.

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Find first occurrence across multiple columns

    what kind of match: exact or partial match?
    by row or by column in range A1:D100?
    Could you post an image or XL2BB mini sheet?

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Find first occurrence across multiple columns

    Quote Originally Posted by TildesleyH View Post
    ... identifies the first occurrence of a string and inputs "y" to an adjacent cell ...
    ???
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-16-2019
    Location
    New Zealand
    MS-Off Ver
    365
    Posts
    44

    Re: Find first occurrence across multiple columns

    Hi again bebo021999,

    Thank you for your assistance, however I have managed to solve this issue myself

    For anyone who stumbles upon this thread with a similar issue, my code is as follows:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Find first occurrence across multiple columns

    Quote Originally Posted by TildesleyH View Post
    Hi again bebo021999,
    Thank you for your assistance, however I have managed to solve this issue myself
    Lots of For Next loop and writting to sheet directly may cause the code supper slow
    I believe that using array will help a lots, esp. working with big data
    If you willing to get a proper and fast solution, try to attach a sample sheet.

+ 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] Find last occurrence of value across two columns and return adjacent value
    By maym in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-28-2022, 07:12 PM
  2. Find the Last Occurrence of a Lookup Value between two columns
    By caves23 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-13-2021, 07:49 AM
  3. [SOLVED] Find Row number of First and Last occurrence matching values in 2 columns
    By muralidaran in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-02-2020, 08:09 AM
  4. [SOLVED] Find unique occurrence of names across a number of columns
    By DPJW in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-21-2016, 09:28 AM
  5. [SOLVED] Find the last occurrence of a value in multiple columns or a matrix
    By jbh001 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-01-2014, 02:07 AM
  6. [SOLVED] Find nth occurrence with multiple criteria
    By Joe Walsh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-05-2013, 11:09 AM
  7. Replies: 3
    Last Post: 08-20-2009, 06:08 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