worksheet selection

G

greg

If I have a few cells selected. And I have a worksheet object to work with.
How can I loop the selected cells?

I normally do
Dim myCell As Range
For Each myCell In Selection.Cells

However from a worksheet, it does not seem like there is a selection.

thanks foe any help
 
N

Norman Jones

Hi Greg,

Your code works for me and I am not sure
that I understand the question.

Perhaps, try something like:

'=============>>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim rCell As Range

Set WB = Workbooks("MyBook1.xls") '<<==== CHANGE
Set SH = WB.Sheets("Foglio1") '<<==== CHANGE
Set Rng = SH.Range("A1:A10") '<<==== CHANGE

For Each rCell In Rng.Cells
'\\ Do something, e.g.
MsgBox Prompt:=rCell.Address(0, 0)
Next rCell
End Sub
'<<=============
 
T

Tim Zych

This is a valid approach and works for me. The problem may possibly be that
the macro is in the wrong place? It should be in a module rather than behind
a worksheet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top