gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
I would like to write a VBA code where if there is a change in column A, it will…
- 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
- 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 SubReplace
<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.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.