Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Excel VBA – how to select column AND row of active cell?

I have been struggling with VBA code that selects entire row and column of active cell. I tried many codes, but all of them failed. I don’t want to make any changes to range, I need to just select it.

How selection after macro should look like:
Selected column and row

Last version of code I came up with, still not working. Any ideas how to achieve it or fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel



Private Sub CommandButton7_Click()

    Dim Column As range
       Set Column = ActiveCell.EntireColumn
    Dim Row As range
       Set Row = ActiveCell.EntireRow
    Dim rng As range
    
    With ActiveSheet
        Set rng = Union(.range(Column), .range(Row))
    End With
    
  rng.Select

    Unload Me
    
End Sub

>Solution :

You were close, but this can done simply with:

With ActiveCell
    Union(.EntireRow, .EntireColumn).Select
End With

Or just a one-liner:

Union(ActiveCell.EntireRow, ActiveCell.EntireColumn).Select
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading