How do you isolate each cell in a selected range?

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
272
I want a user to ctrl-click cells on one worksheet, and from that selection I will find corresponding information on another worksheet.

I know how to set the range to what has been selected and I know how to get the count of what is selected. But what I don't know is how to go through those selected items individually so that I can get the information I ultimately want to get.

So I found this code. However, as it goes through the loop, it simply goes to the cell directly below it and not the next cell in the selected range.

How do I identify the specific cells within the selected range?

Btw, the code between the IF and Else is not what I want; it's just something that was included in the original code.

Code:
Sub DistroList()
Dim Distro As String
Dim pmSelect As Integer
Dim i As Integer

areaCount = Selection.Areas.Count
If areaCount <= 1 Then
 MsgBox "The selection contains " & _
 Selection.Rows.Count & " rows."
Else
 i = 1
 For Each a In Selection.Areas
 MsgBox Cells(i, 4).Value
 i = i + 1
 Next a
End If
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
3,789
Office Version
  1. 365
Platform
  1. Windows
Maybe something like this:

Code:
Dim r As Range

For Each r In Selection
Debug.Print r.Address
Next
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,267
Office Version
  1. 365
Platform
  1. Windows
Depending what cells are selected, maybe
Code:
   Dim Rng As Range, Cl As Range
   For Each Rng In Selection.Areas
      For Each Cl In Rng
         MsgBox Cl.Address
      Next Cl
   Next Rng
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,267
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,215
Messages
5,836,053
Members
430,403
Latest member
RoToR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top