How do you isolate each cell in a selected range?

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
303
Office Version
  1. 365
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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Maybe something like this:

Code:
Dim r As Range

For Each r In Selection
Debug.Print r.Address
Next
 
Upvote 0
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
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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
Back
Top