ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   worksheet selection (https://www.excelbanter.com/excel-programming/411632-worksheet-selection.html)

greg

worksheet selection
 
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



JLGWhiz

worksheet selection
 
Check this out:

http://support.microsoft.com/kb/141762

"greg" wrote:

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




Norman Jones[_2_]

worksheet selection
 
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
'<<=============


---
Regards.
Norman
"greg" wrote in message
...
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




Tim Zych

worksheet selection
 
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.

--
Tim Zych
www.higherdata.com
Compare data in workbooks and find differences with Workbook Compare
A free, powerful, flexible Excel utility

"greg" wrote in message
...
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






All times are GMT +1. The time now is 07:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com