Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

I would like to write a VBA code where if there is a change in column A, it will…

  1. User

    I would like to write a VBA code where if there is a change in column A, it will calculate the formula in the last empty cell of column K

  2. Assistant

    Here's the VBA code to achieve this:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim lastRow As Long, formulaCell As Range
        If Target.Column = 1 Then 'checks if the change is in column A
            lastRow = Cells(Rows.Count, "K").End(xlUp).Row 'finds last used row in column K
            Set formulaCell = Range("K" & lastRow + 1) 'sets the next empty cell in column K as the formula cell
            formulaCell.Formula = "=<PUT YOUR FORMULA HERE>" 'put your formula here between quotation marks
        End If
    End Sub
    

    Replace <PUT YOUR FORMULA HERE> with your desired formula.

    Simply copy and paste this code into the Worksheet module where you want this to apply (right-click on the tab of the worksheet and select "View Code").

    This code will trigger every time there is a change in column A and will calculate the formula in the last empty cell of column K.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.