Monday, June 20, 2016

Excel VBA- Form design

EXCEL VBA INPUT FORM DESIGN






Option Explicit

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdOK_Click()
    Dim lngRow As Long
    Dim CNTRL As Control
 
    Sheet1.Range("A1:F1").Value = Array("Region", "Brand", "Color", "Price", "Units", "Dates")
    Sheet1.Range("A1:F1").Font.Bold = True
    lngRow = Sheet1.Range("A1").End(xlDown).Row + 1
    ''Check if a text box is empty?
    For Each CNTRL In Me.Controls
        If TypeName(CNTRL) = "TextBox" Then
            If CNTRL.Text = "" Then
                MsgBox "CNTRL.SetFocus"
                CNTRL.SetFocus
                Exit Sub
            End If
'            Debug.Print CNTRL.Text
        End If
    Next
 
    ''Pass data from text boxes to cells
    With Sheet1
        .Range("A" & lngRow) = TextBoxRegion.Value
        .Range("B" & lngRow) = TextBoxBrand.Value
        .Range("C" & lngRow) = TextBoxColor.Value
        .Range("D" & lngRow) = TextBoxPrice.Value
        .Range("E" & lngRow) = TextBoxUnits.Value
        .Range("F" & lngRow) = TextBoxDate.Value
    End With
End Sub

Sub pShowUF()
    UserFormX.Show
End Sub




No comments:

Post a Comment

Hot Topics