I have a research database where the code below will react to a typed reference and return instances from the database. It all works well. My problem is that it will not function if another workbook is open. Can I force it to read the "ewc codes" sheet.
Failing that I will have to look into the workbook opening in its own instance of excel as it is very handy to have open when using other workbooks.
Any help[ appreciated
I can attach workbook if required
Private Sub TextBox6_Change()
Dim a, i As Long, w(), n As Long, strExclude As String
Product.ListBox4.Clear
If Product.TextBox6.Value = "" Then Exit Sub
If Product.ComboBox2.Value = "Yes" Then
strExclude = "20*"
ElseIf Product.ComboBox2.Value = "No" Then
strExclude = "19*"
Else
strExclude = ""
End If
a = Sheets("ewccodes").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
If (UCase$(a(i, 3)) Like "*" & UCase$(Product.TextBox6.Value) & "*" Or _
UCase$(a(i, 4)) Like "*" & UCase$(Product.TextBox6.Value) & "*") And _
Not a(i, 6) Like strExclude Then
n = n + 1
ReDim Preserve w(1 To UBound(a, 2), 1 To n)
For ii = 1 To UBound(a, 2)
w(ii, n) = a(i, ii)
Next
End If
Next
If n > 0 Then Product.ListBox4.Column = w
End Sub
Bookmarks