Need Help - What am I missing? ListBox in UserForm will not allow me. . .

Lidsavr

Active Member
Joined
Jan 10, 2008
Messages
330
I am running Excel 2007 and writing code that both 2007 and 2003 users run.

I have a report that sometimes list multiple occurrences of a condition. I have written a routine that searches the data for duplicates and returns the duplicates in a ListBox. I can then choose which of the duplicate items I want to use in my final report.

The Problem:
The ListBox works great the first time and I can select and item (line items becomes blue when I click on it in the ListBox); however, when the code continues with a loop and comes around to the ListBox again, new data appears like I want to have happen, but I cannot select any item in the ListBox (will not turn blue when I click on an item and the code will not continue).

Any ideas why this is happening? Can you help me correct or change my code?

I've included code below. The ListBox code is in the Run_Form subroutine.

Code:
Private Sub Start_Search()
    Range("E1").Select
Call Add_Data
End Sub
--------------------------------------------------------------------------
Private Sub Add_Data()
    Do
        ActiveCell.Offset(1, 0).Select
        If ActiveCell.Value = "ARCT00615" Then
            Application.Run "Search_Dups"
        Workbooks("Raw Data.xls").Activate
            On Error Resume Next
            x = Application.WorksheetFunction.VLookup(ActiveCell.Offset(0, -4).Value, _
                Workbooks("ARCT00615_BOM.xls").Worksheets("ARCT00615") _
                .Range("A1:I65536"), 7, False)
            If Err.Number <> 0 Then
                x = ""
            End If
            ActiveCell.Offset(0, 16).Value = x
            x = Application.WorksheetFunction.VLookup(ActiveCell.Offset(0, -4).Value, _
                Workbooks("ARCT00615_BOM.xls").Worksheets("ARCT00615") _
                .Range("A1:I65536"), 6, False)
            If Err.Number <> 0 Then
                x = ""
            End If
            ActiveCell.Offset(0, 17).Value = x
        End If
    Loop Until ActiveCell.Value = ""
End Sub
--------------------------------------------------------------------------
Private Sub Search_Dups()
    On Error GoTo 0
    MyStr = ActiveCell.Offset(0, 11).Value
    Workbooks("ARCT00615_BOM.xls").Activate
    Range("H:H").Select
    Set SRng = Selection
    x = Application.WorksheetFunction.CountIf(SRng, MyStr)
    If x > 1 Then
        Selection.Find(What:=MyStr, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("A10").Value = ActiveCell.Offset(0, -6).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("B10").Value = ActiveCell.Offset(0, -3).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("C10").Value = ActiveCell.Offset(0, -2).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("D10").Value = ActiveCell.Offset(0, -1).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("E10").Value = ActiveCell.Value
        Selection.Find(What:=MyStr, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("A11").Value = ActiveCell.Offset(0, -6).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("B11").Value = ActiveCell.Offset(0, -3).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("C11").Value = ActiveCell.Offset(0, -2).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("D11").Value = ActiveCell.Offset(0, -1).Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data") _
            .Range("E11").Value = ActiveCell.Value
        Workbooks("Raw Data.xls").Worksheets("Temp_Data").Activate
        Cells.Select
        Cells.Columns.AutoFit
        Range("A1").Select
        ActiveCell.Value = Range("A10").Value & "-" & Range("B10").Value _
            & "-" & Range("C10").Value & "-" & Range("D10").Value _
            & "-" & Range("E10").Value
        ActiveCell.Offset(1, 0).Select
        ActiveCell.Value = Range("A11").Value & "-" & Range("B11").Value _
            & "-" & Range("C11").Value & "-" & Range("D11").Value _
            & "-" & Range("E11").Value
        Range("A1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Set SRng2 = Selection
        Call Run_Form
     End If
End Sub
Private Sub Run_Form()
    With UserForm1.ListBox1
        .BoundColumn = 1
        .ColumnCount = 1
        .ControlSource = "'Temp_Data'!A6"
        .IntegralHeight = True
        .MultiSelect = 0
        .RowSource = SRng2.Address
    End With
    If TypeName(Selection) = "Range" Then
        UserForm1.Show
    End If
End Sub
--------------------------------------------------------------------------
Private Sub Record_Choice1()
    Sheets("Raw Data").Activate
    ActiveCell.Offset(0, 16).Value = Sheets("Temp_Data").Range("D10").Value
    ActiveCell.Offset(0, 17).Value = Sheets("Temp_Data").Range("C10").Value
Call Clear_Temp_Data
End Sub
--------------------------------------------------------------------------
Private Sub Record_Choice2()
    ActiveCell.Offset(0, 16).Value = Sheets("Temp_Data").Range("D11").Value
    ActiveCell.Offset(0, 17).Value = Sheets("Temp_Data").Range("C11").Value
Call Clear_Temp_Data
End Sub
--------------------------------------------------------------------------
Private Sub Clear_Temp_Data()
    Sheets("Temp_Data").Activate
    Cells.Select
    Cells.ClearContents
    Selection.ColumnWidth = 8.43
    Range("A1").Select
    Sheets("Raw Data").Select
    SRng2.Clear
Call Add_Data
End Sub

In addition, here is the UserForm code:

Code:
Private Sub ContinueButton1_Click()
    If Range("$A$6").Value = Range("$A$1").Value Then
        Unload UserForm1
        Application.Run "Record_Choice1"
    End If
    
    If Range("$A$6").Value = Range("$A$2").Value Then
        Unload UserForm1
        Application.Run "Record_Choice2"
    End If
End Sub

Thank you,

Charles
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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