ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Searching for a string and then performing an action if present (https://www.excelbanter.com/excel-programming/346399-searching-string-then-performing-action-if-present.html)

matpj[_24_]

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 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

--
matp
-----------------------------------------------------------------------
matpj's Profile: http://www.excelforum.com/member.php...fo&userid=2107
View this thread: http://www.excelforum.com/showthread.php?threadid=48756


antoka05[_2_]

Searching for a string and then performing an action if present
 

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")


--
antoka05
------------------------------------------------------------------------
antoka05's Profile: http://www.excelforum.com/member.php...o&userid=29024
View this thread: http://www.excelforum.com/showthread...hreadid=487568



All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com