问题描述:

I want to check a cell for specific text in a formula.

If it contains that text I want to select the next cell.

If it doesn't contain that text I want to perform some formatting.

I have tried

If StrComp("A1", "D:\I Stuff\Ser*", vbTextCompare) > 0 Then

'this is checking that "D:\I Stuff\Ser" does exist in A1...

ActiveCell.Offset(0, 0).Range("A1:H1").Select

It doesn't seem to select/find the string in the formula.

网友答案:

The InStr function should be used to check for the string within the Range.Formula property.

dim rng as range
set rng = activecell
if cbool(instr(1, rng.formula, "D:\I Stuff\Ser", vbTextCompare)) Then
    rng.resize(1, 8).Select
else
    'not found. do something else
end if

You may also be interested in How to avoid using Select in Excel VBA macros for more methods on getting away from relying on select and activate to accomplish your goals.

相关阅读:
Top