So I've done some Javascript editing before but it's been a while since then. I know I should know how to do this but the solution has escaped me. All I'm trying to do is make an ElseIf command so that certain formulas are put into cells that need them based on values from a UserForm.
This is what I have:
Private Sub addItem_Click()
Dim the_sheet As Worksheet
Dim table_object_row As ListRow
Set the_sheet = Sheets("NewOrder")
'find first empty row in database
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
'check for a part number
If Trim(Me.txtItem.Value) = "" Then
Me.txtItem.SetFocus
MsgBox "Please enter an item"
End If
If Trim(Me.txtPerc.Value) = "" Then
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With table_object_row
' .Unprotect Password:="password"
.Range(1, 1).Value = Me.txtItem.Value
.Range(1, 2).Value = Me.txtSKU.Value
.Range(1, 3).Value = Me.txtPrice.Value
.Range(1, 4).Value = Me.txtPerc.Value
.Range(1, 5).Value = Me.txtAdjust.Value
.Range(1, 6).Value = Me.txtQTY.Value
.Range(1, 8).Formula = "=F*E"
End With
'clear the data
Me.txtItem.Value = ""
Me.txtSKU.Value = ""
Me.txtPrice.Value = ""
Me.txtPerc.Value = ""
Me.txtAdjust.Value = ""
Me.txtQTY.Value = ""
Me.txtItem.SetFocus
Else
If Trim(Me.txtAdjust.Value) = "" Then
With table_object_row
.Range(1, 1).Value = Me.txtItem.Value
.Range(1, 2).Value = Me.txtSKU.Value
.Range(1, 3).Value = Me.txtPrice.Value
.Range(1, 4).Value = Me.txtPerc.Value
.Range(1, 5).Formula = "=(C*(1-D))"
.Range(1, 6).Value = Me.txtQTY.Value
.Range(1, 8).Formula = "=F*E"
' .Protect Password:="password"
End With
'clear the data
Me.txtItem.Value = ""
Me.txtSKU.Value = ""
Me.txtPrice.Value = ""
Me.txtPerc.Value = ""
Me.txtAdjust.Value = ""
Me.txtQTY.Value = ""
Me.txtItem.SetFocus
End If
End If
End Sub
.Range(1, 8).Formula = "=F5*E5", e.g. Perhaps you have to tell what object in theUserFormyou want to get the value from (you are already doing that as well).I know I should know how to do this but the solution has escaped me.Did you do your research? Did you check msdn or inbuilt Excel help or Google on the syntax ofIF?