Consulting

Results 1 to 4 of 4

Thread: Delete Text Between 2 Ranges - Input Box

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Delete Text Between 2 Ranges - Input Box

    Evening folks,

    I made an input box to delete text between 2 ranges but its fallen flat and fails to start up ?

        Sub DeleteBetween2Ranges()
    
    
        Dim myRange As Range
        
        Dim oText1 As String
        Dim oText2 As String
      
        oText1 = InputBox("Enter First Word :")
        If Len(oText) = 0 Then
        Exit Sub
        End If
    
        
        oText2 = InputBox("Enter Second Word :")
         If Len(oText) = 0 Then
        Exit Sub
        End If
    
        If Len(oText) = 0 Then
        Exit Sub
        End If
    
        
        
        Set myRange = ActiveDocument.Range
        With myRange.Find
        
       
        Do While .Execute(FindText:="oText1*oText2", MatchWildcards:=True)
        
    
        myRange.Text = ""
        
        myRange.Collapse
        Loop
        End With
      
        End Sub
    I would like my input box as I have to always change the delete between the 2 ids

    Any ideas welcome
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    >"oText1*oText2"

    oText1 & "*" & oText2

  3. #3
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    >If Len(oText) = 0 Then


    If Len(oText1) = 0 Then
    and
    If Len(oText2) = 0 Then

  4. #4
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    As Usual,
    I spent ages looking for this bug - that i couldnt see
    If Len(oText) = 0 Then
    Exit Sub
    End If

    I forgot to put the oText1 in brackets

    Also this did the trickk
    oText1 & "*" & oText2

    thank you Mana

    and all have great evening
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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