Exclude specific words

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I would like to exclude the words "Call" or "Put" when running this code. How can I modify this code to achieve this?

VBA Code:
    For Each rCell In Wks.Range("C7:C" & X)
        If Not Dic.exists(Split(rCell.Value, "-")(1)) Then
            Dic.Add Split(rCell.Value, "-")(1), Nothing
        End If
    Next rCell
    
    cbT3.List = Dic.keys
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try
VBA Code:
Sub Exclude_Call_Put()
X = 10
Set Wks = Sheets("Sheet1")
 For Each rCell In Wks.Range("C7:C" & X)
 K = Split(rCell.Value, "-")(1)
        If Not Dic.exists(K) And InStr(1, K, "Put") = 0 And InStr(1, K, "Call") = 0 Then
            Dic.Add Split(rCell.Value, "-")(1), Nothing
        End If
    Next rCell
   
    cbT3.List = Dic.keys
End Sub
 
Last edited:
Upvote 1
Possibly something along these lines:

VBA Code:
Sub Test()

Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary")
Dim wks As Worksheet: Set wks = ThisWorkbook.Worksheets("Sheet1")
Dim x As Long, i As Long, tmp As String, arr As Variant

With wks
    x = .Cells(.Rows.Count, "C").End(xlUp).Row
    arr = .Range("C7:C" & x).Value
End With

For i = LBound(arr) To UBound(arr)
    Debug.Print arr(i, 1)
    tmp = Split(arr(i, 1), "-")(1)
    If tmp = "Call" Or tmp = "Put" Then
        'Do nothing
    Else
        dict(tmp) = 1
    End If
Next

cbT3.List = Dict.keys

End Sub
 
Upvote 1
I have words like BO-Calls , BO-Puts , BO-Vertical, etc. Realizing there are too many variable words I would like to include with "Calls" & "Puts", How can I adjust it that would eliminate any that has "O-" ?
 
Upvote 0
Try
VBA Code:
Sub Exclude_Call_Put()
X = 12
Set Wks = Sheets("Sheet1")
Set Dic = CreateObject("Scripting.dictionary")
 For Each rCell In Wks.Range("C7:C" & X)
 If InStr(1, rCell, "-") > 0 Then
 K = Split(rCell.Value, "-")(1)
        If Not Dic.exists(K) And InStr(1, rCell, "O-") = 0 Then
            Dic.Add Split(rCell.Value, "-")(1), Nothing
        End If
 End If
 Next rCell
cbT3.List = Dic.keys
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,216,057
Messages
6,128,520
Members
449,456
Latest member
SammMcCandless

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