Hi Dok112 and Doug,
I set the Break in Class and it stops at the same statement, where I
originally show the UserForm1 in the main macro. It looks like it's trying
to repeat that step and not proceeding to the next one.
I don't have any with statements in the userform, so it may have an issue
with the Object Variable part. NOTE: in the macro, the next step after the
Load UserForm1 command is a section named POPULATE:
Not sure if this matters.
Here's the UserForm code I have. Below I copied the section of the main
macro that loads the Userform, with the statements immediately preceding and
following it:
Option Explicit
Private Sub userform_initialize()
Dim AllCells As Range, Cell As Range
Dim myStart As Range
Dim destWB As Workbook
Dim searchltr As String, testltr As String
Dim sourceVal As String
Dim sourceWB As Workbook
Dim sourceRange As Range
Dim x As Long
Dim a As Long
Set sourceWB = Workbooks("CustomerData.xls")
Set destWB = Workbooks("ODonnell Sales Model17.xls")
Set sourceRange = destWB.Sheets("Customer Data").Range("b6")
If sourceRange.Value = "" Then
MsgBox "Please enter a Name"
sourceRange.Select
Exit Sub
End If
If Len(sourceRange.Value) >= 1 Then searchltr = _
UCase(Left(sourceRange.Value, 1))
sourceWB.Activate
Set myStart = Range("D

")
x = myStart.End(xlDown).Row - myStart.Row + 1
For a = 2 To x
Set AllCells = Range("d" & a)
Let testltr = UCase(Left(AllCells.Value, 1))
If searchltr = testltr Then
Me.ListBox1.AddItem AllCells.Value
End If
Next a
' Show the UserForm
UserForm1.Show
End Sub
Private Sub CANCEL_Click()
Unload Me
End Sub
Private Sub ListBox1_Click()
Dim AllCells As Range, Cell As Range
Dim myStart As Range
Dim destWB As Workbook
Dim searchltr As String, testltr As String
Dim sourceVal As String
Dim sourceWB As Workbook
Dim sourceRange As Range
Dim a As Long
Dim rng As Range
Dim rng1 As Range
Dim x As Long
Dim keyRange As Range
If Me.ListBox1.ListIndex = -1 Then Exit Sub
Set sourceWB = Workbooks("CustomerData.xls")
Set destWB = Workbooks("ODonnell Sales Model17.xls")
Set sourceRange = destWB.Sheets("Customer Data").Range("B6")
If Len(sourceRange.Value) >= 1 Then searchltr = _
UCase(Left(sourceRange.Value, 1))
sourceWB.Activate
Set myStart = Range("D

")
x = myStart.End(xlDown).Row - myStart.Row + 1
For a = 2 To x
Set AllCells = Range("D" & a)
If AllCells.Value = Me.ListBox1.Value Then
Set rng = AllCells
Exit For
End If
Next a
If Not rng Is Nothing Then
Application.Goto rng, True
Else
MsgBox "Not found"
End If
Set keyRange = destWB.Sheets("Sheet3").Range("A7")
ActiveCell.EntireRow.Copy _
Destination:=keyRange
Unload Me
End Sub
______________________________________________________________
Code before and after loading userform:
With sourceWB.Sheets(1).Range("D

")
Set rng = .Find(What:=sourceRange.Value, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValue, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
If Not rng Is Nothing Then
rng.EntireRow.Copy destrange
Msg = sourceRange.Value & "Loading."
MsgBox (Msg)
GoTo POPULATE
Else
Msg = sourceRange.Value & " Not Found. Would you like to lookup?" ' Define
message.
Style = vbYesNo ' Define buttons.
Title = "Customer Not Found" ' Define title.
Ctxt = 1000 ' Define topic
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then GoTo ender ' User chose No, so end.
End If
Load UserForm1
POPULATE:
Application.ScreenUpdating = False
destWB.Activate
Sheets("Sheet3").Visible = True
Sheets("Calculations").Visible = True
Sheets("Customer Data").Visible = True
Sheets("Calculations").Unprotect
Sheets("Customer Data").Unprotect