Results 1 to 4 of 4

InStr function not working when extracting characters to right of character in VBA

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    InStr function not working when extracting characters to right of character in VBA

    Hey all,

    I try to extract all the content after the character V in cell G and place it in cell m as part of procedure:

    Sub findDefendant()
    
    Dim RENums As Object
    Dim LValue  As String
    
    
    
    Set RENums = CreateObject("VBScript.RegExp")
    
    
    RENums.Pattern = "DEFENDANT"
    
    
      Dim lngLastRow As Long
      lngLastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
       
    
      Dim i
    
      For i = 1 To lngLastRow
    
        If RENums.Test(Range("J" & i).Value) Then
        
            pos = InStr("V", Range("G" & i))
        
            LValue = Range("K" & i)
    
            If pos <> 0 Then 'if V found continue
               LValue2 = Right(Range("G" & i), Len(Range("G" & i)) - pos)
            End If
    
        
            Range("N" & i).Value = LValue
            Range("O" & i).Value = LValue2
            
        
            
        End If
    
      Next i
    
    End Sub
    It does not put the values right of "V" from G into cell O. In fact, even though cell G does contain "V" in it, it leaves cell O completely blank for all instances.
    Last edited by johnmerlino; 02-25-2011 at 01:59 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1