My code works with UserForm, where all information will be written before saving in a table. I want to add two formulas with IF statement, but I keep getting a compile error.
I don't know why it checks that code at all... It shouldn't. It should only be pasted to the right column among with text from the user form.
Can someone tell me what I'm doing wrong here?
I tried .Formula and .Value but nothing works.
All the time "Error while compiling".
Private Sub SaveData()
'Copy input values to sheet.
Dim lrow As Long
Dim ws As Worksheet
Set ws = Tabelle1
Dim i As Integer
lrow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).row
For i = 1 To lrow
If ws.Cells(i, 1).Value = Me.E1GCharge.Value Then
MsgBox "Diese Charge ist schon vorhanden, bitte einfach Bestand
aktualisieren"
Exit Sub
End If
Next i
With ws
.Cells(lrow, 1).Value = Me.E1GCharge.Value
.Cells(lrow, 3).Value = Me.E1GMatName.Value
.Cells(lrow, 4).Value = Me.E1Gtype.Value
.Cells(lrow, 5).Value = Me.E1GMatNumber.Value
.Cells(lrow, 6).Value = Me.E1GExpiryDate.Value
.Cells(lrow, 6).NumberFormat = "mmm.yyyy"
.Cells(lrow, 7).Value = Me.E1GBoxPcs.Value
.Cells(lrow, 8).Value = Me.E1GAmmount.Value
.Cells(lrow, 9).Value = Me.E1GUnit.Value
.Cells(lrow, 10).Value = Me.E1Gkonz.Value
'IF Statement compiling Error "=IF([@[Rest Tubes]]<>"N/A""
.Cells(lrow, 11).FormulaLocal = "=IF([@[Rest Tubes]]<>"N/A",[@Pieces]-[@[Auslagerung Total]]/[@[Number of tubes Ammount]],[@Pieces]-[@[Auslagerung pcs]])"
'IF Statement compiling Error "=IF([@[Rest Tubes]]="N/A""
.Cells(lrow, 12).FormulaLocal = "=IF([@[Number of tubes Ammount]]="N/A";"N/A";[@Pieces]*[@[Number of tubes Ammount]]-[@[Auslagerung Total]])"
End With
'Clear input controls.
Me.E1GMatName.Value = ""
Me.E1Gtype.Value = ""
Me.E1GMatNumber.Value = ""
Me.E1GExpiryDate.Value = ""
Me.E1GBoxPcs.Value = ""
Me.E1GAmmount.Value = ""
Me.E1Gkonz.Value = ""
Me.E1GUnit.Value = ""
Call GetData
End Sub
#N/Aerror because if so that's not the correct way.