gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
Can I have a vba code that checks if no cell in the sheet is selected and if so it then…
- User
Can I have a vba code that checks if no cell in the sheet is selected and if so it then selcets the first empty cell in column b
- Assistant
Yes, you can use the following VBA code to achieve this:
Sub SelectFirstEmptyCellInColumnB() 'Check if any cell is selected If Selection.Cells.Count = 1 Then If IsEmpty(Selection) Then 'If no cell is selected or selected cell is empty, then select the first empty cell in column B Range("B1").Select Do Until IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop End If End If End SubYou can call this subroutine whenever you need to check whether any cell is selected, and if not, select the first empty cell in column B.