I can't seem to figure out what is causing Excel to freak out over the sequence below:
Subroutine initializes the userform:
Sub CreatePOUserForm()
uf_1_CreatePO.Show
End Sub
Userform code:
Private Sub UserForm_Initialize()
Dim ws As Worksheet
Dim iRow As Long
Dim rngSuppliers As Range
Dim Cell As Range
Dim UniqueSupp As Collection
Dim Supp As Variant
iRow = 2
Set ws = ThisWorkbook.Sheets("Suppliers")
Set rngSuppliers = ws.Range("A" & iRow, ws.Range("A" & iRow).End(xlDown))
Set UniqueSupp = New Collection
On Error Resume Next
For Each Cell In rngSuppliers.Cells
UniqueSupp.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
For Each Supp In UniqueSupp
Controls.Item("ComboBox1").AddItem Supp
Next Supp
End Sub
User selection is passed through to MakeOrderTbl(Supp as String) subroutine:
Private Sub CommandButton1_Click()
Dim Supp As String
Supp = Me.Controls.Item("ComboBox1").Value
Unload Me
Call MakeOrderTbl(Supp)
End Sub
I have "Stop" lines throughout the MakeOrderTbl(Supp as String) sub because I'm still tinkering with it. After stepping through a few stops, if I reset/end the procedure in the middle of MakeOrderTbl and then try to save the file, Excel crashes. I'm assuming the problem has to do with the way I'm initializing the userform, because if I run the Private Sub Userform_Initialize routine straight from the VBE, it doesn't cause a crash.
Any ideas how to fix this? I've been searching the internet for the last two days and have tried a code cleaner and have also tried AdLoki's suggestion found here: http://www.excelforum.com/excel-prog...een-saved.html
I also tried initializing the userform with:
Sub Maint_btn_CreatePO_Click()
uf_1_CreatePO.Show
End Sub
Sheetname "Maint" and button name "btn_CreatePO". I later saw this referenced without the sheetname+underscore prefix and have tried that as well.
Thanks for your thoughts.
Bookmarks