Get text after position in string

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to get the text after a string which can be found at any point in a cell.

The full string is 'VIDEO PRESENT: *YES/NO/NOT APPLICABLE'

What I need to extract is the answer, i.e. YES, NO or NOT APPLICABLE. The issue I have is that people have to delete the part of the answer which isn't relevant, leaving their answer, but I am getting all sorts of weird answers such as, *YES, /NO, *YES/ and any other variation you can think of!

So is there an efficient VBA method to grab the answer?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Did you think of using a validation dropdown list?
 
Upvote 0
I can't do that unfortunately, the data is pulled out of another system and exported to Excel so what I get is what they've answered in the other system if that makes sense - they're not inputting the data directly onto a spreadsheet.
 
Upvote 0
If you need a code solution for some reason I think I'd use a Select Case block and the instr function to find the word, and Mid function to extract it. Once extracted, where does it go?
 
Upvote 0
Is VIDEO PRESENT: in one column and the options in another, or is it all one text string in one cell?
 
Upvote 0
Thanks for the replies guys - Georgiboy; it's all in the same cell
 
Upvote 0
Are the options always the same or do you have different options for some questions?
 
Upvote 0
Perhaps you could run a small sub that would add the validation cells in the column next to your data, the users could then select those options:
VBA Code:
Sub test()
    Dim rng As Range
    
    Set rng = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    
    With rng.Offset(, 1).Validation
        .Delete
        .Add xlValidateList, xlValidAlertStop, , "YES,NO,NOT APPLICABLE"
    End With
End Sub

The above looks at the data in column A and places the options dropdown in column B
 
Upvote 0
This is the basis of what I'm saying
VBA Code:
Sub GetAnswer()
Dim i As Integer

i = InStr(Sheets("Sheet5").Range("A2"), "YES")
If i = 0 Then i = InStr(Sheets("Sheet5").Range("A2"), "NO")
If i = 0 Then i = InStr(Sheets("Sheet5").Range("A2"), "NOT APPLICABLE")

Select Case i
     Case 17 ' YES
          Sheets("Sheet5").Range("A2") = Mid(Sheets("Sheet5").Range("A2"), i, 3)
        
     Case 22 ' NO
   
     Case 25 ' NOT APPLICABLE

End Select

End Sub
Obviously unfinished but if of interest, can continue. It changes this
'VIDEO PRESENT: *YES/NO/NOT APPLICABLE
into
YES
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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