Você está na página 1de 13

Dim iRow As Long

Dim ws As Worksheet

Set ws = Worksheets("Process_Database")

' find first empty row in database

iRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row

'copy the data to the database

ws.Cells(iRow, 2).Value = Me.ComboBox4.Value

ws.Cells(iRow, 3).Value = Me.TextBox1.Value

ws.Cells(iRow, 4).Value = Me.ComboBox7.Value

ws.Cells(iRow, 5).Value = Me.TextBox17.Value

ws.Cells(iRow, 6).Value = Me.TextBox29.Value

ws.Cells(iRow, 8).Value = Me.TextBox23.Value

ws.Cells(iRow, 9).Value = Me.TextBox31.Value

' Check user input

If Me.ComboBox4.Value = "" Then

MsgBox "Please enter the PART NUMBER.", vbExclamation, "Staff Expenses"

Me.ComboBox4.SetFocus

Exit Sub

End If

' Write data to worksheet

RowCount = Worksheets("Material_Database").Range("Q3").CurrentRegion.Rows.Count

With Worksheets("Material_Database").Range("Q3")

.Offset(0, 0).Value = Me.ComboBox1.Value

End With
Private Sub UserForm_Activate()

With Application

Me.Top = .Top

Me.Height = .Height

End With

End Sub

Private Sub UserForm_Click()

With Me

'This will create a vertical scrollbar

.ScrollBars = fmScrollBarsVertical

'Change the values of 2 as Per your requirements

.ScrollHeight = .InsideHeight * 2.5

End With

End Sub
With ComboBox6

If .ListIndex = -1 Then Exit Sub

Select Case .Value

Case "Sheet Metal / Plate_Group Nesting"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = True

TextBox7.Visible = True

Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = True

CommandButton4.Visible = True

CommandButton5.Visible = False

CommandButton11.Visible = False

Case "Sheet Metal / Plate_Nesting/part"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True
Label17.Visible = True

TextBox7.Visible = True

Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = True

CommandButton4.Visible = False

CommandButton5.Visible = False

CommandButton11.Visible = False

Case "Sheet Metal / Plate_Envelope Size"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = True

TextBox7.Visible = True

Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = False

Label24.Visible = True
Label25.Visible = True

TextBox12.Visible = False

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton5.Visible = True

CommandButton11.Visible = False

Case "Part weight + Scrap %"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = True

TextBox7.Visible = True

Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton6.Visible = False
CommandButton11.Visible = True

Case "Round bar"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = False

TextBox7.Visible = False

Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton5.Visible = True

CommandButton11.Visible = False

Case "Square bar"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True
TextBox6.Visible = True

Label17.Visible = False

TextBox7.Visible = False

Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton5.Visible = True

CommandButton11.Visible = False

Case "Rectangle bar"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = True

TextBox7.Visible = True

Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = True
Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton5.Visible = True

CommandButton11.Visible = False

Case "Rectangle Tube"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = True

TextBox7.Visible = True

Label18.Visible = True

TextBox8.Visible = True

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton5.Visible = True
CommandButton11.Visible = False

Case "Square Tube"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = True

TextBox7.Visible = True

Label18.Visible = True

TextBox8.Visible = True

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton5.Visible = True

CommandButton11.Visible = False

Case "Round tube / pipe"

Label15.Visible = True

TextBox5.Visible = True

Label16.Visible = True

TextBox6.Visible = True

Label17.Visible = True

TextBox7.Visible = True
Label18.Visible = False

TextBox8.Visible = False

Label22.Visible = True

Label23.Visible = True

Label24.Visible = True

Label25.Visible = True

TextBox12.Visible = True

TextBox13.Visible = True

TextBox14.Visible = True

CommandButton3.Visible = False

CommandButton4.Visible = False

CommandButton5.Visible = True

CommandButton11.Visible = False

End Select

End With

' Write data to worksheet

RowCount = Worksheets("Material_Calc").Range("E18").CurrentRegion.Rows.Count

With Worksheets("Material_Calc").Range("E18")

.Offset(0, 0).Value = Me.ComboBox6.Value

End With

Set rngfind = Sheet2.[D23:Z57]

On Error Resume Next

Label15.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 2, False)

Label16.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 3, False)

Label17.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 4, False)

Label18.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 5, False)

Label19.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 6, False)


Label14.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 8, False)

Label22.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 10, False)

Label23.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 11, False)

Label24.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 12, False)

Label25.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 13, False)

Label26.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 14, False)

Label27.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 15, False)

Label28.Caption = WorksheetFunction.VLookup(ComboBox6.Value, rngfind, 7, False)


Private Sub CommandButton1_Click()

Dim i As Long

For i = 2 To Application.WorksheetFunction.CountA(Sheet3.Range("A:A"))

For x = 1 To 8

If Sheet3.Cells(i, "B").Value = Me.TextBox2.Text Then

Sheet3.Cells(i, x).Value = Me("textbox" & x).Value

End If

Next x

Next i

End Sub

Private Sub CommandButton2_Click()

Dim iRow As Long

Dim ws As Worksheet

Set ws = Worksheets("Production_Site")

' find first empty row in database

iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

'copy the data to the database

ws.Cells(iRow, 1).Value = Me.TextBox1.Value

ws.Cells(iRow, 2).Value = Me.TextBox2.Value

ws.Cells(iRow, 3).Value = Me.TextBox3.Value

ws.Cells(iRow, 4).Value = Me.TextBox4.Value

ws.Cells(iRow, 5).Value = Me.TextBox5.Value

ws.Cells(iRow, 6).Value = Me.TextBox6.Value

ws.Cells(iRow, 7).Value = Me.TextBox7.Value

ws.Cells(iRow, 8).Value = Me.TextBox8.Value

End Sub
Private Sub TextBox2_AfterUpdate()

Dim i As Long

For i = 2 To Application.WorksheetFunction.CountA(Sheet3.Range("A:A"))

For x = 1 To 8

If Sheet3.Cells(i, "B").Value = TextBox2.Text Then

Me("Textbox" & x).Value = Sheet3.Cells(i, x).Value

End If

Next x

Next i

End Sub

Private Sub TextBox11_AfterUpdate()

Dim i As Long

For i = 2 To Application.WorksheetFunction.CountA(Sheet3.Range("A:A"))

For x = 1 To 13

If Sheet3.Cells(i, "A").Value = TextBox11.Text Then

Me("Textbox" & x).Value = Sheet3.Cells(i, x).Value

End If

Next x

Next i

End Sub

Você também pode gostar