+ Reply to Thread
Results 1 to 3 of 3

textbox change event sheet reference will not work if another workbook open

Hybrid View

nigelog textbox change event sheet... 02-17-2017, 06:16 AM
BellyGas Re: textbox change event... 02-17-2017, 06:20 AM
nigelog Re: textbox change event... 02-17-2017, 08:48 AM
  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    textbox change event sheet reference will not work if another workbook open

    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
    Last edited by nigelog; 02-17-2017 at 08:48 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: textbox change event sheet reference will not work if another workbook open

    Try changing

        a = Sheets("ewccodes").Cells(1).CurrentRegion.Value
    to

        a = ThisWorkbook.Sheets("ewccodes").Cells(1).CurrentRegion.Value

  3. #3
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: textbox change event sheet reference will not work if another workbook open

    thankyou for an efficient fix. Sorted now

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] LostFocus event for TextBox - how to make it work
    By kmeld in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-02-2013, 03:51 AM
  2. [SOLVED] Change Workbook Open event Zoom via VBA
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2012, 08:58 PM
  3. Workbook sheet change event prompts save
    By pprseller in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-29-2009, 02:12 PM
  4. Sheet Change Event wont work
    By Strugglin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2009, 10:35 AM
  5. [SOLVED] Change the work sheet name in a formula by using cell reference
    By Neel in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-12-2006, 04:25 AM
  6. Hide Sheet using Workbook Open Event
    By johnhildreth@citynet.net in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-09-2005, 03:30 PM
  7. [SOLVED] Change workbook sheet reference using cell A1 to change a vairable
    By Reed in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-20-2005, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1