Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Test for formula in cell

Excel 2000

How do I get the following formula:

If ActiveCell.Offset(0, -4).Formula = " *" Then

to test if the formula/value (hard coded) in the cell is of the form

" ####"

(two spaces followed by four of any digits)?

Two spaces followed by anything would be good enough at present. The
above code produces false on " 1234" when I think it ought to produce
true. Is "*" usable as a wild card?

TIA

Fred Holmes
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Test for formula in cell

Hi Fred

Yes, * can be used as a wildcard but you need to change the '=' to 'Like'

If ActiveCell.Offset(0, -4).Formula Like " *" Then

HTH

Trevor Williams

"Fred Holmes" wrote:

Excel 2000

How do I get the following formula:

If ActiveCell.Offset(0, -4).Formula = " *" Then

to test if the formula/value (hard coded) in the cell is of the form

" ####"

(two spaces followed by four of any digits)?

Two spaces followed by anything would be good enough at present. The
above code produces false on " 1234" when I think it ought to produce
true. Is "*" usable as a wild card?

TIA

Fred Holmes

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Test for formula in cell

Hi Fred

Yes, * can be used as a wildcard. You need to change the '=' to 'Like'.
If ActiveCell.Offset(0, -4).Formula Like " *" Then

HTH
Trevor Williams

"Fred Holmes" wrote:

Excel 2000

How do I get the following formula:

If ActiveCell.Offset(0, -4).Formula = " *" Then

to test if the formula/value (hard coded) in the cell is of the form

" ####"

(two spaces followed by four of any digits)?

Two spaces followed by anything would be good enough at present. The
above code produces false on " 1234" when I think it ought to produce
true. Is "*" usable as a wild card?

TIA

Fred Holmes

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Test for formula in cell

You can either explicitly test the value:

Sub DataTester()
Dim s As String
s = ActiveCell.Offset(0, -4).Value
l = Len(s)
st = Left(s, 2)
en = Right(s, 4)
If l = 6 And st = " " And IsNumeric(en) Then
MsgBox ("value is good")
Else
MsgBox ("value is not good")
End If
End Sub


or use Like and a pattern match.
--
Gary''s Student - gsnu200856


"Fred Holmes" wrote:

Excel 2000

How do I get the following formula:

If ActiveCell.Offset(0, -4).Formula = " *" Then

to test if the formula/value (hard coded) in the cell is of the form

" ####"

(two spaces followed by four of any digits)?

Two spaces followed by anything would be good enough at present. The
above code produces false on " 1234" when I think it ought to produce
true. Is "*" usable as a wild card?

TIA

Fred Holmes

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Test for formula in cell

as already mentioned, the asterisk is the wildcard for any number of
characters.

if you want specifically to check a space followed by four characters use
LIKE " ????"
or
for space and four digits
LIKE " ####"

HELP on LIKE gives you all these

"Fred Holmes" wrote in message
...
Excel 2000

How do I get the following formula:

If ActiveCell.Offset(0, -4).Formula = " *" Then

to test if the formula/value (hard coded) in the cell is of the form

" ####"

(two spaces followed by four of any digits)?

Two spaces followed by anything would be good enough at present. The
above code produces false on " 1234" when I think it ought to produce
true. Is "*" usable as a wild card?

TIA

Fred Holmes




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Test for formula in cell

Thanks to all for your suggestions. Both methods work well.

Fred Holmes
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test on the format of a cell in a formula ? brunzeg New Users to Excel 1 November 13th 09 11:05 AM
How do I test a cell's formula (ex: Is this cell and Avg or a sum? Karie Excel Worksheet Functions 1 December 26th 08 09:54 PM
Formula that will test text conditions in a single cell Prohock Excel Worksheet Functions 10 April 4th 06 10:21 PM
IF Function to test formula in a cell Fred Holmes Excel Worksheet Functions 5 November 18th 05 12:04 AM
Test a cell for a formula present Trebor Retrac Excel Discussion (Misc queries) 1 May 30th 05 05:11 PM


All times are GMT +1. The time now is 04:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"