• Cell After Update function (Excel 2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Cell After Update function (Excel 2003)

    Author
    Topic
    #432767

    Hi

    I have a table with columns for (amongst other things) amount and tax plus a column with a drop down list with options No (default) and Yes. I’d like to be able to run some code so that if a user selects Yes the amount is reduced by tax and tax is entered in its column. I guess I also need code to reverse this if the user changes the cell back to No.

    Can anyone point me in the right direction?

    David

    Viewing 1 reply thread
    Author
    Replies
    • #1015998

      Why do you need a macro? A formula with an IF would seem to fit the need.

      Could you elaborate on your setup and what you need exactly?

      Steve

      • #1016013

        Thanks for the prompt response.

        Let us say that cell B1 is blank and the user enters a figure of

        • #1016019

          Right-click the sheet tab and select View Code.
          Enter or paste the following code:

          Private Sub Worksheet_Change(ByVal Target As Range)
          Dim oCell As Range
          Const dblVat = 0.175
          Application.EnableEvents = False
          If Not Intersect(Range(“B1:B20”), Target) Is Nothing Then
          For Each oCell In Intersect(Range(“B1:B20”), Target).Cells
          If IsNumeric(oCell) Then
          If oCell.Offset(0, 1) = “Yes” Then
          oCell.Offset(0, 2) = oCell * dblVat / (1 + dblVat)
          oCell = oCell / (1 + dblVat)
          End If
          End If
          Next oCell
          End If
          If Not Intersect(Range(“C1:C20”), Target) Is Nothing Then
          For Each oCell In Intersect(Range(“C1:C20”), Target).Cells
          If IsNumeric(oCell.Offset(0, -1)) Then
          If oCell.Offset = “Yes” Then
          oCell.Offset(0, 1) = oCell.Offset(0, -1) * dblVat / (1 + dblVat)
          oCell.Offset(0, -1) = oCell.Offset(0, -1) / (1 + dblVat)
          Else
          oCell.Offset(0, -1) = oCell.Offset(0, -1) + oCell.Offset(0, 1)
          oCell.Offset(0, 1).ClearContents
          End If
          End If
          Next oCell
          End If
          Application.EnableEvents = True
          End Sub

          Adjust the ranges as needed. See attached sample workbook.

          • #1016034

            I am once again filled with admiration. Exactly what I was looking for. It will take me a little while to get it into my existing spreadsheet but the sample proves it works.

            I’d love to know what you do for a living. Man, you’re always there within minutes with awesome responses.

            Regards
            David

    • #1015999

      How is tax calculated? Or how does “and tax is entered in its column” work?

    Viewing 1 reply thread
    Reply To: Cell After Update function (Excel 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: