+ Reply to Thread
Results 1 to 2 of 2

Searching for a string and then performing an action if present

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Posts
    164

    Searching for a string and then performing an action if present

    I have a pivot table that I am copying and pasting into a new worksheet so I can insert some columns etc.

    I need to 'search' row 4 for the existence of the word "Documentation". If I find it then insert an entire column tot he right of it.

    If documentation does not exist then do nothing.

    can anyone suggest some code that I could use for this?
    thanks,
    Matt

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    you can do so:
    insert a module in your workbook, then put this function in the module

    Function searchMyString(celle As Range, testo As String)
    searchMyString = "NO"
    For Each cl In celle.Cells
    If InStr(cl, testo) > 0 Then
    searchMyString = "OK"
    Exit For
    End If
    Next

    End Function

    and then, in your worksheet, for example in cell A1, you can use this formula
    =searchMyString(A4:Z4;"Documentation")

    and in cell A1 will be displayed 'OK' if the string 'documentation' is present in cells from A4 to Z4, else in A1 will be displyed 'NO'

    Of course you can change the range of cells in wich to find text, for example:

    =searchMyString(A4:BA4;"Documentation")

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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