gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
I would like an excel VBA code that When page is activated, Search column J for the last…
- User
I would like an excel VBA code that When page is activated, Search column J for the last cell that is not empty Copy the value in the the cell above the same row in column K and paste into column K on the same row where column J is not empty
- Assistant
Sure! Here's a VBA code that accomplishes the task you described:
Private Sub Worksheet_Activate() Dim lastRow As Long Dim cellAbove As Range ' Find the last non-empty cell in column J lastRow = Cells(Rows.Count, "J").End(xlUp).Row ' Check if lastRow is greater than 1 to ensure there is a cell above it If lastRow > 1 Then ' Copy the value in the cell above the last non-empty cell in column J Set cellAbove = Cells(lastRow - 1, "K") cellAbove.Copy ' Paste the value into the same row in column K where column J is not empty Range("K" & lastRow).PasteSpecial xlPasteValues End If ' Clear the clipboard Application.CutCopyMode = False End SubTo add this code to your Excel worksheet:
- Press
Alt + F11to open the Visual Basic for Applications (VBA) editor - In the Project Explorer window, find the worksheet where you want to perform this action.
- Right-click on the worksheet and select "View Code."
- In the code window, paste the above code.
- Press
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.