Search code examples
vbaexcelvb6

VBA How to get Multiple Selections with .Selection


I haven't been able to find a helpful solution to this. Maybe someone on here might know the answer. My macro requires the user to have a source and destination cell. To do this the selects the source, and then hold ctrl and clicks another cell. This creates multiple selections and I can't seem to access both of them. When I use the Selection range I only have the first cell in the range. Is there another selection range, or how can I get the 2nd cell? Does anyone have a clue?


Solution

  • What you need is reference to Areas collection of Selection. It will go this way:

    'for first cell:
    Selection.Areas(1).Address
    'for second cell:
    Selection.Areas(2).Address
    

    Both will return address of cells but you could change it accordingly.