Help looping a form

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I work for a company that packages numerous products with different brand names. Sometimes we package the same product under a different brand name but the Lot number, expiration date, and product code are still the same. Because of us packaging product this way, this is considered a split lot.

When the user opens up the workbook a messagebox opens up and asks if this is a split lot. If the user clicks no, a form named frmPackageYield appears. However, when the user clicks yes I need that same userform to load and after the user clicks the submit button the form will reload disabling certain controls after the first submit click.

I have a userform that asks the user various questions such as:

Select Production Line(Production Line are radio buttons)
Select Product: (combobox)
Product Code: (textbox)
Lot Code: (textbox)
Expiration Date: (textbox)
Quantity Issued to Packaging (textbox)
Cartons Issued: (textbox)
Samples: (textbox)
Damaged: (textbox)

When the user clicks the Submit button the first time, the data is entered an excel spreadsheet template. Then the form reloads asking the same questions with the exception the following textboxes which should be set to .enabled = false and those textboxes are
product code
Lot code
expiration date
Quantity Issued to Packaging

So my question is:
How can I reload/reuse the same userform inside a For Loop making the above changes on the second loop and when the user clicks submit it finds the last selection cell and adds one line each time the form has to loop?

Code:
'Declares variable names
    Dim ans As String
    Dim ansSplit As String
    Dim i As Integer
    
    ans = MsgBox("Is this a split Lot?", vbQuestion + vbYesNo, "Split Lot")
    
    If ans = vbNo Then
        frmPackageYield.Show vbModeless
    Else
        ansSplit = InputBox("How many times does this lot split?", "Split Lot")
        For i = 1 To ansSplit
            frmPackageYield.Show vbModeless
           [B]CODE NEEDED HERE[/B]


        Next i
    End If
    
End Sub

The code for the submit button.
Code:
Private Sub cmdbtnSubmit_Click()
    
    Dim str As String
    Dim found As Range


    
    str = Me.cmbPrdCde.Value
    Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Activate
    str = Replace(Split(str, "(")(1), ")", vbNullString)
    
    Select Case True
        Case Is = optSat
            Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Activate
            Set found = Worksheets("Product_Info").Range("B3", Range("B" & Rows.Count).End(xlUp)).Find(str)
        Case Is = optIM
            Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Activate
            Set found = Worksheets("Product_Info").Range("N3", Range("N" & Rows.Count).End(xlUp)).Find(str)
        Case Is = optCober
            Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Activate
            Set found = Worksheets("Product_Info").Range("J3", Range("J" & Rows.Count).End(xlUp)).Find(str)
        Case optOhl2
            Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Activate
            Set found = Worksheets("Product_Info").Range("F3", Range("F" & Rows.Count).End(xlUp)).Find(str)
        Case optPunch
            Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Activate
            Set found = Worksheets("Product_Info").Range("V3", Range("V" & Rows.Count).End(xlUp)).Find(str)
        Case optOhl5
            Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Activate
            Set found = Worksheets("Product_Info").Range("R3", Range("R" & Rows.Count).End(xlUp)).Find(str)
    End Select
    
    Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Activate
    Worksheets("Exhibit E Bulk mt").Activate
    Worksheets("Exhibit E Bulk mt").Range("H14").Value = Date
    Worksheets("Exhibit E Bulk mt").Range("C6").Value = "'" & Me.TxtBxBlkBlnd.Value
    Worksheets("Exhibit E Bulk mt").Range("C9").Value = str
    Worksheets("Exhibit E Bulk mt").Range("C11").Value = Me.txtbxLtNum.Value
    Worksheets("Exhibit E Bulk mt").Range("C13").Value = Me.txtbxExpDte.Value
    Worksheets("Exhibit E Bulk mt").Range("F18").Value = Me.txtbxQtyIss.Value
    Worksheets("Exhibit E Bulk mt").Range("B23").Value = Me.txtbxCartonsIss.Value
    Worksheets("Exhibit E Bulk mt").Range("B28").Value = Me.txtbxSamples.Value
    Worksheets("Exhibit E Bulk mt").Range("B32").Value = Me.txtbxDamaged.Value
    Worksheets("Exhibit E Bulk mt").Range("B36").Value = Me.txtbxRedress.Value
    Worksheets("Exhibit E Bulk mt").Range("D32").Value = "1"
    
    Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004_ver_19_3.xlsm").Sheets("Product_Info").Activate
    
    If found Is Nothing Then
        MsgBox ("Nothing found")
    Else
        Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Range("A23") = Cells(found.Row, 3).Value
        Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Range("A28") = Cells(found.Row, 3).Value
        Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Range("A32") = Cells(found.Row, 3).Value
        Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Range("A36") = Cells(found.Row, 3).Value
        Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Range("D23") = Cells(found.Row, 3).Value
        Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Range("D28") = Cells(found.Row, 3).Value
        Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Range("D36") = Cells(found.Row, 3).Value
    End If
    Unload Me
    Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Sheets("Exhibit E Bulk mt").Activate
    
End Sub

So for any confusion that this explanation may have caused and thank you.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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