+ Reply to Thread
Results 1 to 5 of 5

Search along row and paste into destination cell

Hybrid View

  1. #1
    Registered User
    Join Date
    07-22-2017
    Location
    Melbourne
    MS-Off Ver
    2016
    Posts
    7

    Search along row and paste into destination cell

    Hi there,

    I'm very new to VBA and would really appreciate help/advice. Attached is a simplified version of my spreadsheet but essentially I would like a macro which does the following:

    1. Search along row to see where text is found in the 'Applicable' columns
    2. Where found, list column heading(s) to 'Applicable Tables' column (Column K) using line breaks
    3. Continue to next row and repeat

    Hopefully that makes sense, happy to explain further if needed.

    Table Screenshot2.PNG


    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search along row and paste into destination cell

    run in attached workbook with {CTRL} t

    Provided that sheet has same structure, this will work for as many tables as you want

    VBA
    - finds value "Applicable Tables" in row 1 to determine last column
    - loop through all rows with value in cell in column A (starting at row 3)
    - checks if "Yes" in any column
    - checks if value in cell row 2 = "Applicable"
    - adds value of cell in row 1 to the destination cell

    Sub tiubacker()
        Dim ws As Worksheet, rng As Range, cel As Range, target As Range, check As Range
        Dim lastCol As Long, r As Long
        Set ws = Sheets("Data")
         
    With ws
        Set rng = .Range("A3", .Range("A" & Cells.Rows.Count).End(xlUp))
        
        lastCol = .Rows("1:1").Find("Applicable Tables", LookIn:=xlFormulas).Column
        
        For Each cel In rng
            Set target = .Cells(cel.Row, lastCol)
            r = cel.Row
            target.Value = ""
            For c = 2 To lastCol
                Set check = .Cells(r, c)
                If check.Value = "Yes" And .Cells(2, c) = "Applicable" Then
                    If target.Value = "" Then
                        target.Value = .Cells(1, c).Value
                    Else
                        target.Value = target.Value & Chr(10) & .Cells(1, c).Value
                    End If
                End If
            Next c
        Next cel
        
    End With
        
    End Sub
    Attached Files Attached Files
    Last edited by kev_; 07-23-2017 at 05:44 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Search along row and paste into destination cell

    UDF can be used in K column. is it ok .

  4. #4
    Registered User
    Join Date
    07-22-2017
    Location
    Melbourne
    MS-Off Ver
    2016
    Posts
    7

    Re: Search along row and paste into destination cell

    @Kev, Thank you very much for the response. I'm going to attempt to translate it into my actual spreadsheet and will let you know soon how I get on.

    @kvsrinivasamurthy, I'm not quite sure what you mean?

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search along row and paste into destination cell

    UDF = user defined function
    - which is VBA code that can be used as a regular formula in your worksheet

    perhaps something like this:
    =ApplicableTables(C3,E3,G3,I3) in cell K3 and copy down

    The VBA would then put the relevant table names in each cell

+ 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. Copy from static destination & paste to dynamic destination
    By Marbleking in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2015, 09:31 AM
  2. Copy and Paste w/ Paste Destination determined by Cell Value
    By jeremy9er7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-10-2014, 10:42 AM
  3. Destination cell is empty after copy and paste
    By wingnut74 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2014, 05:56 PM
  4. [SOLVED] Cell linking: Destination cell must perform a search for data
    By r2fro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2014, 05:50 AM
  5. [SOLVED] Copy, paste, refresh, loop with one destination cell
    By GriffinCarpenter in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-14-2013, 01:45 PM
  6. Using destination filepaths listed in cell contents opposing to coding destination
    By kuraitori in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2009, 01:23 PM
  7. paste only if destination cell nonblank
    By edwardpestian in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2006, 04:55 PM

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