Searching for a string and then performing an action if present

  • Thread starter Thread starter matpj
  • Start date Start date
M

matpj

I have a pivot table that I am copying and pasting into a new workshee
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,
Mat
 
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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top