Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba- excel- "for each" what row/col (cell) is it looking at?

Can you please tell me how to get the row and col of the cell that the
'for each cell in userrange' command in vba in excel is Processing.

ex:

a1=5
a2=4

function print("a1:a2")

for each cell in userrange
debug.print cell.Value
' I hope to be able to print a1 = 5 and a2=4
next
end function

will print
5
4

But how can I tell that it is processing a1 or a2 and put THAT valu
in a variable?

What IS cell.Value? is cell a class? and does this class have cell.re
or cell.row or ANYthing?

thank yo

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default vba- excel- "for each" what row/col (cell) is it looking at?

Hi
cell.row
cell.column

--
Regards
Frank Kabel
Frankfurt, Germany


Can you please tell me how to get the row and col of the cell that

the
'for each cell in userrange' command in vba in excel is

Processing.

ex:

a1=5
a2=4

function print("a1:a2")

for each cell in userrange
debug.print cell.Value
' I hope to be able to print a1 = 5 and a2=4
next
end function

will print
5
4

But how can I tell that it is processing a1 or a2 and put THAT value
in a variable?

What IS cell.Value? is cell a class? and does this class have

cell.ref
or cell.row or ANYthing?

thank you


---
Message posted from http://www.ExcelForum.com/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default vba- excel- "for each" what row/col (cell) is it looking at?

In a
For Each cell In rng
type of statement, the code is iterating through each cell within the range
one at a time, so cell refers to a single cell range object. Hence

cell.row will return the row of the cell being process
cell.column returns the column
cell.value returns the value in that cell
cell.address(false,false) returns the cell address (e.g. A1)

The code you want seems to be

For Each cell In userrange
Debug.Print cell.Value
'or maybe MsgBox cell.value
Next cell

If you want to return these values as a worksheet function, you need more
complex processing to handle the array.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"jimx " wrote in message
...
Can you please tell me how to get the row and col of the cell that the
'for each cell in userrange' command in vba in excel is Processing.

ex:

a1=5
a2=4

function print("a1:a2")

for each cell in userrange
debug.print cell.Value
' I hope to be able to print a1 = 5 and a2=4
next
end function

will print
5
4

But how can I tell that it is processing a1 or a2 and put THAT value
in a variable?

What IS cell.Value? is cell a class? and does this class have cell.ref
or cell.row or ANYthing?

thank you


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default vba- excel- "for each" what row/col (cell) is it looking at?

Sub Main()
Dim rng as Range
set rng = range("A1:A2")
Range("A1").Value = 5
Range("A2").Value = 4
myPrint rng
End Sub

function myPrint(userrange as Range)
dim cell as Range
for each cell in userrange
debug.print cell.Address(0,0) & " = " & cell.Value
next
end function

--
Regards,
Tom Ogilvy


"jimx " wrote in message
...
Can you please tell me how to get the row and col of the cell that the
'for each cell in userrange' command in vba in excel is Processing.

ex:

a1=5
a2=4

function print("a1:a2")

for each cell in userrange
debug.print cell.Value
' I hope to be able to print a1 = 5 and a2=4
next
end function

will print
5
4

But how can I tell that it is processing a1 or a2 and put THAT value
in a variable?

What IS cell.Value? is cell a class? and does this class have cell.ref
or cell.row or ANYthing?

thank you


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Help!!! Enter "7" in a cell and Excel changes the "7" to "11" immediately!!! [email protected] Excel Discussion (Misc queries) 3 January 5th 07 02:18 PM
convert "15000" to "Fifteen thousand" in excel cell? anurag Excel Worksheet Functions 1 May 4th 06 07:58 AM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM
how can I make an excel cell "mark" or "unmark" when clicked on? Rick Excel Discussion (Misc queries) 6 January 8th 06 10:15 PM


All times are GMT +1. The time now is 01:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"