Search string containing two specific text

reubanrao93

New Member
Joined
Dec 7, 2020
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Evening gurus,

I'm trying to run a formula on a adjacent cell column if the source cell contains two specific text which are defined. Formula 1 is to straight forward and will not be using InSTR function, however for Formula 2, the two specific text are "MODRETSUBUNIT" and "OPONEMS". A sample of the source cell is as below:

MMLCommand:MODRETSUBUNIT:DEVICENO=13,SUBUNITNO=1,TILT=0,OPONEMS="JMANOJK",IPOFEMSWS="172.26.84.98";

I've been using InSTR but it doesnt fetch the correct formula. For the souce cell above instead of Formula 2, the destination cell will contain Formula 1 instead. Is there something I'm missing here?

Sheets("OUTPUT").Range("N:N").Select
ActiveCell.Formula = "=MID(J1,(LEN(J1)-(LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))-4)),((LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))-4)-(LEN(LEFT(J1,LEN(J1)-SEARCH("";"",J1))))))" <--- Formula 1
LRw = Range("J" & Rows.Count).End(xlUp).Row
Range(ActiveCell, Cells(LRw, ActiveCell.Column)).FillDown

Application.ScreenUpdating = True

Sheets("OUTPUT").Range("N:N").Select
If InStr(1, (Range("J1").Value), "MODRETSUBUNIT:") > 0 & InStr(1, (Range("J1").Value), ",OPONEMS=") > 0 Then 'MODBTSRETSUBUNIT standalone & OPMODE [ISSUE]
ActiveCell.Formula = "=MID(J1,(LEN(J1)-(LEN(LEFT(J1,LEN(J1)-SEARCH(""TNO="",J1)))-4)),((LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))-4)-LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))))" <--- Formula 2
End If
LRw = Range("J" & Rows.Count).End(xlUp).Row
Range(ActiveCell, Cells(LRw, ActiveCell.Column)).FillDown
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How about
VBA Code:
With Sheets("OUTPUT")
   lRw = .Range("J" & Rows.Count).End(xlUp).Row
   If InStr(1, .Range("J1").Value, "MODRETSUBUNIT:") > 0 And InStr(1, .Range("J1").Value, ",OPONEMS=") > 0 Then
      .Range("N1:N" & lRw).Formula = "=MID(J1,(LEN(J1)-(LEN(LEFT(J1,LEN(J1)-SEARCH(""TNO="",J1)))-4)),((LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))-4)-LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))))"
   Else
      .Range("N1:N" & lRw).Formula = "=MID(J1,(LEN(J1)-(LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))-4)),((LEN(LEFT(J1,LEN(J1)-SEARCH(""ILT="",J1)))-4)-(LEN(LEFT(J1,LEN(J1)-SEARCH("";"",J1))))))"
   End If
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,214,846
Messages
6,121,905
Members
449,054
Latest member
luca142

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top