Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

Can I have a vba code that checks if no cell in the sheet is selected and if so it then…

  1. 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

  2. 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 Sub
    

    You 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.