ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Statement (https://www.excelbanter.com/excel-programming/318040-if-statement.html)

Pete

If Statement
 
Hi,

I am a novice with VBA and am trying to put an if statement which detects
whether the cell contains the word "total" within the cell (there will be
text before and after it).

I have tried :
If ActiveCell.value = "*total*" Then
but this doesn't work.

Many Thanks in advance
Pete

Don Guillett[_4_]

If Statement
 
try

If InStr(ActiveCell, "total") 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Pete" wrote in message
...
Hi,

I am a novice with VBA and am trying to put an if statement which detects
whether the cell contains the word "total" within the cell (there will be
text before and after it).

I have tried :
If ActiveCell.value = "*total*" Then
but this doesn't work.

Many Thanks in advance
Pete




Don Guillett[_4_]

If Statement
 
Or this to account for case
If InStr(ActiveCell, UCase(TOTAL)) 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
try

If InStr(ActiveCell, "total") 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Pete" wrote in message
...
Hi,

I am a novice with VBA and am trying to put an if statement which

detects
whether the cell contains the word "total" within the cell (there will

be
text before and after it).

I have tried :
If ActiveCell.value = "*total*" Then
but this doesn't work.

Many Thanks in advance
Pete






Tom Ogilvy

If Statement
 
The first will find "total" and the second will find nothing (since the
variable TOTAL) is uninitialized, but assuming you meant

If InStr(ActiveCell, UCase("TOTAL")) 0 Then MsgBox "its there"
it would find only TOTAL

to do a case insensitive search

You probably meant
If InStr(Ucase(ActiveCell), "TOTAL") 0 Then MsgBox "its there"

or better:

if Instr(1,ActiveCell,"total",vbTextCompare) then
MsgBox "its there"
End If

--
Regards,
Tom Ogilvy



"Don Guillett" wrote in message
...
Or this to account for case
If InStr(ActiveCell, UCase(TOTAL)) 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
try

If InStr(ActiveCell, "total") 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Pete" wrote in message
...
Hi,

I am a novice with VBA and am trying to put an if statement which

detects
whether the cell contains the word "total" within the cell (there will

be
text before and after it).

I have tried :
If ActiveCell.value = "*total*" Then
but this doesn't work.

Many Thanks in advance
Pete








Don Guillett[_4_]

If Statement
 
this is what I meant
If InStr(Ucase(ActiveCell), "TOTAL") 0 Then MsgBox "its there"



--
Don Guillett
SalesAid Software

"Tom Ogilvy" wrote in message
...
The first will find "total" and the second will find nothing (since the
variable TOTAL) is uninitialized, but assuming you meant

If InStr(ActiveCell, UCase("TOTAL")) 0 Then MsgBox "its there"
it would find only TOTAL

to do a case insensitive search

You probably meant
If InStr(Ucase(ActiveCell), "TOTAL") 0 Then MsgBox "its there"

or better:

if Instr(1,ActiveCell,"total",vbTextCompare) then
MsgBox "its there"
End If

--
Regards,
Tom Ogilvy



"Don Guillett" wrote in message
...
Or this to account for case
If InStr(ActiveCell, UCase(TOTAL)) 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
try

If InStr(ActiveCell, "total") 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Pete" wrote in message
...
Hi,

I am a novice with VBA and am trying to put an if statement which

detects
whether the cell contains the word "total" within the cell (there

will
be
text before and after it).

I have tried :
If ActiveCell.value = "*total*" Then
but this doesn't work.

Many Thanks in advance
Pete









Pete

If Statement
 
That works great !
Thanks for your help guys.
Pete

"Don Guillett" wrote:

this is what I meant
If InStr(Ucase(ActiveCell), "TOTAL") 0 Then MsgBox "its there"



--
Don Guillett
SalesAid Software

"Tom Ogilvy" wrote in message
...
The first will find "total" and the second will find nothing (since the
variable TOTAL) is uninitialized, but assuming you meant

If InStr(ActiveCell, UCase("TOTAL")) 0 Then MsgBox "its there"
it would find only TOTAL

to do a case insensitive search

You probably meant
If InStr(Ucase(ActiveCell), "TOTAL") 0 Then MsgBox "its there"

or better:

if Instr(1,ActiveCell,"total",vbTextCompare) then
MsgBox "its there"
End If

--
Regards,
Tom Ogilvy



"Don Guillett" wrote in message
...
Or this to account for case
If InStr(ActiveCell, UCase(TOTAL)) 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
try

If InStr(ActiveCell, "total") 0 Then MsgBox "its there"

--
Don Guillett
SalesAid Software

"Pete" wrote in message
...
Hi,

I am a novice with VBA and am trying to put an if statement which
detects
whether the cell contains the word "total" within the cell (there

will
be
text before and after it).

I have tried :
If ActiveCell.value = "*total*" Then
but this doesn't work.

Many Thanks in advance
Pete











All times are GMT +1. The time now is 02:47 PM.

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