View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Delete cells with 0 as the tenth digit

On Sun, 8 Feb 2009 16:59:00 -0800, PointerMan
wrote:

Here's what the data looks like, and part of that formula worked to
conditional format them. This is all in one cell, by the way...

12-30-08 SHIP 74A350834-2019 37
12-30-08 SHIP 901-069-113-134 3
12-31-08 0 70302-02159-120 83
12-31-08 0 901-069-114-174 4


If I understand you correctly, the above is in one cell, and you want a formula
which will return those strings that do NOT have a "0" in the tenth place:

12-30-08 SHIP 74A350834-2019 37
12-30-08 SHIP 901-069-113-134 3

Also in one cell.

To do that, you can use a UDF (user defined function).

To enter the function, <alt-F11 opens the VB Editor. Ensure your project is
highlighted in the project explorer window, then Insert/Module and paste the
code below into the window that opens.

Then enter this formula in some cell:

=RegexSub(A1,"(\n|^).{9}0.*","")

Replace A1 with the appropriate cell reference.

Be sure to format the cell to "wrap text".

=============================================
Option Explicit
Function RegexSub(Str As String, SrchFor As String, ReplWith As String, _
Optional CaseSensitive As Boolean = False, _
Optional Gl As Boolean = True, _
Optional ML As Boolean = True) As String
Dim objRegExp As Object
Set objRegExp = CreateObject("vbscript.regexp")
With objRegExp
.Pattern = SrchFor
.IgnoreCase = CaseSensitive
.Global = Gl
.MultiLine = ML
End With
RegexSub = objRegExp.Replace(Str, ReplWith)
End Function
===========================================


--ron