Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50061

Replacing part of text in cell

$
0
0
I have a column of cells like this:
Code:

!
router bgp 99999
 !
 address-family ipv4 vrf CCCCCC-123456
  no synchronization
  redistribute connected
  redistribute static
  neighbor CUSTOMER123456 peer-group
  neighbor CUSTOMER123456 remote-as 65222
  neighbor CUSTOMER123456 send-community both
  neighbor CUSTOMER123456 soft-reconfiguration inbound
  neighbor CUSTOMER123456 route-map CUSTOMER:CUSTDIST-123456-IN in
  neighbor CUSTOMER123456 route-map NUVOX-MGMT-DENY out
  neighbor CUSTOMER123456 maximum-prefix 1000
  neighbor 172.16.0.2 peer-group CUSTOMER123456
  neighbor 172.16.0.2 activate
  default-information originate
 exit-address-family
 !
exit
!

I need to change it to this:
Code:

!
router bgp 99999
 !
 address-family ipv4 vrf CCCCCC-123456
  no synchronization
  redistribute connected
  redistribute static
  neighbor CUSTOMER123456 peer-group
  neighbor CUSTOMER123456 remote-as 65222
  neighbor CUSTOMER123456 send-community both
  neighbor CUSTOMER123456 soft-reconfiguration inbound
  neighbor CUSTOMER123456 route-map CUSTOMER:CUSTDIST-123456-IN in
  neighbor CUSTOMER123456 route-map NUVOX-MGMT-DENY out
  neighbor CUSTOMER123456 maximum-prefix 1000
  neighbor 172.16.0.2 peer-group CUSTOMER123456
  ! neighbor 172.16.0.2 activate
  ! default-information originate
 exit-address-family
 !
exit
!

I am able to do the "default-information originate" line quite nicely with this:
Code:

    DoNotWant = Array("  default-information originate")
    With Columns("V")
        For i = 0 To UBound(DoNotWant)
            .Replace What:=DoNotWant(i), Replacement:="  !  default-information originate", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        Next i
    End With

However, the "neighbor IP activate" line stumps me.

Something like this works for where I am now, but later I would like to know how to do it correctly:
Code:

    DoNotWant = Array(" neighbor *.*.*.* activate")
    With Columns("V")
        For i = 0 To UBound(DoNotWant)
            .Replace What:=DoNotWant(i), Replacement:=" ! neighbor IP-HERE activate", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        Next i
    End With

Gives me the actual text "neighbor IP-HERE activate" and not "neighbor A.B.C.D activate" (keeping whatever IP was there to begin with.)

Viewing all articles
Browse latest Browse all 50061

Trending Articles