Search code examples
excelunselectvba

Unselecting a range from a selected data set


I am trying to unselect empty columns from my selection and save the desired selection as a new Range object.

This is my Current Selection

and this is what I desire

Please help me out as Google search isn't helping and I am not able to find any such methods that would solve the case.


Solution

  • Selection.Cells(1).CurrentRegion.Select
    

    Selection refers to all your selected cells. Each selection will surely contain atleast a cell. Your selection may contain 100 cells or may be 20 or may be 5. But it will surely have 1 cell in it. That code is targeting the first cell in selection and identifying the current region (Data's associated with that first cell) and selecting it.