Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks to all for your suggestions. Both methods work well.
Fred Holmes |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Test on the format of a cell in a formula ? | New Users to Excel | |||
How do I test a cell's formula (ex: Is this cell and Avg or a sum? | Excel Worksheet Functions | |||
Formula that will test text conditions in a single cell | Excel Worksheet Functions | |||
IF Function to test formula in a cell | Excel Worksheet Functions | |||
Test a cell for a formula present | Excel Discussion (Misc queries) |