![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Having a problem substituting a variable into code. I'm trying to replace the word COMPLETE with the variable t which also happens to be the word COMPLETE. x is defined as boolean and when I use the variable, I keep getting a false value when it should in fact be true. Any help appreciated.
x = Evaluate("=NOT(ISERROR(SEARCH(""COMPLETE""," & usedcell.Address & ",1)))") x = Evaluate("=NOT(ISERROR(SEARCH(" & t & "," & usedcell.Address & ",1)))") thanks Matt |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Quote:
Try something like the following: Code:
Sub test() Dim x As Boolean, t t = "COMPLETE" On Error Resume Next x = Not IsEmpty(WorksheetFunction.Search(t, ActiveCell, 1)) On Error GoTo 0 MsgBox x End Sub However, please note that I did *not* use the .Address property, as this is searching for a string, not a range reference. In essence, you were searching for "COMPLETE" in "$A$1" rather than in cell A1. To be more precise, replace your UsedCell.Address with UsedCell.Value or just UsedCell in the above code. Let us know if this works for you. Bye, Jay |
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Thanks Jay
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|