error with code

  • Thread starter Thread starter Mauro
  • Start date Start date
M

Mauro

I have the following code:

Range("A2").Select

ActiveWorkbook.Sheets("Main").Activate

Range("A2").Select

Do

If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True

ActiveCell.Value = txtData.Value
ActiveCell.Offset(0, 1) = UCase(txtPax.Value)
ActiveCell.Offset(0, 2) = txtDeparture.Value
ActiveCell.Offset(0, 3) = UCase(txtTratta.Value)
ActiveCell.Offset(0, 4) = txtTariffa.Value
ActiveCell.Offset(0, 5).Value = (txtTasse.Value) - (txtTariffa.Value)
ActiveCell.Offset(0, 6) = UCase(txtAgente.Value)

I need to introduce a variation to this, namely:

if txtTariffa.Value=0 (or empty) then "PT" else
ActiveCell.Offset(0, 5).Value = (txtTasse.Value) - (txtTariffa.Value)

What is the right way to make it work?

thanks

mauro
 
One way:

If IsEmpty(txtTariffa.Value) Or txtTariffa.Value = 0 Then
ActiveCell.Offset(0, 5).Value = "PT"
Else
ActiveCell.Offset(0, 5).Value = txtTasse.Value - txtTariffa.Value
End If
 
If txtTariffa may be blank or have text, one way

If IsEmpty(txtTariffa.Value) Then
ActiveCell.Offset(0, 5).Value = "PT"
ElseIf IsNumeric(txtTariffa.Value) Then
If txtTariffa.Value = 0 Then
ActiveCell.Offset(0, 5).Value = "PT"
Else
ActiveCell.Offset(0, 5).Value = _
txtTasse.Value = txtTariffa.Value
End If
End If
 
Back
Top