List all selected cells in a Excel

How to write a macro to show all the selected cells in a current workbook ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:

what do you mean with "show all selected cells"? If you select the cells, you can already see them, so in what way do you want to "show" them?

Can you explain what you want to achieve? What is the bigger picture?

cheers, teylyn
AXISHKAuthor Commented:
Suppose the 3 cells in the attached file is selected, how to collect the values of all cells when I run the macro ? I want to do some calcuation for them.

NorieAnalyst Assistant Commented:
This code will put all the values from the selected cells in array.

Not sure it's what you want but it might give you a start.
Sub GetSelectedValues()
Dim rng As Range
Dim cl As Range
Dim arrVals()
Dim I As Long

    Set rng = Selection
    For Each cl In rng
        ReDim Preserve arrVals(I)
        arrVals(I) = cl.Value
        I = I + 1
    Next cl
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
You could use a for/each loop along the lines of

Dim cel As Range

For Each cel In Selection
    ' your calculation, for example assign a value to each cell
    cel = cel.value * 1

Open in new window

AXISHKAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.