Excel Mileage Form

  Graham. 12:37 20 Feb 2008

I have Miles in column C, Cost in Column D at 15.5 pence per mile. I need a Macro to automatically enter Cost, please.

  VoG II 12:44 20 Feb 2008

Right click the sheet tab, View Code. Copy and paste in

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then
Application.EnableEvents = False
Target.Offset(0, 1).Value = Target.Value * 0.155
Target.Offset(0, 1).NumberFormat = "$#,##0.00"
Application.EnableEvents = True
End If
End Sub

then close the code window.

  Graham. 13:36 20 Feb 2008

Not working as expected. There was some text already there, I deleted it and pasted yours. Should I be able to click a cell in column D for the calculation to be made?
At the top of the Code window, I have Worksheet and Change.

  VoG II 13:41 20 Feb 2008

If you enter a mileage in a cell in column C the macro will put the cost into the same row in column D.

Don't worry about the Worksheet and Change at the top, although if you click the arrow to the right of Change you'll see the other exciting event procedures that are available :o)

  Graham. 13:46 20 Feb 2008

OK, it's working now. I had to re-enter the existing data. Thanks again.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

The Evil Within 2 review-in-progress

InVision Studio takes on Adobe XD and Sketch

Camera tips to take better iPhone photos

Comment transformer un iPhone en borne Wi-Fi ?