LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Looping thru Sheets without activating

Hi Myles,

Just to add, you may, of course, pass a range which represents all the cells
on the sheet, e.g.:

Set c = sh.cells

---
Regards,
Norman



"Myles" wrote in
message ...

Hi Norman,
I was musing over what happened when I applied the Call idea to my
project.
Using your last tip-off, the structure of my coding becomes:

Sub MainCode()
Dim sh As Worksheet
Dim c As Range

For each sh in WorkSheets
For each c in sh.Range("a:a")

Call RecalculateRowScore(c)

Next
Next
End sub

Sub RecalculateRowScore(rng as Range)

If Instr(rng, "-")=0 Then
rng.Offset(0,1).value=Len(rng)*Asc(Mid(rng,1,1))
ElseIf Instr(rng, "-")0 Then
rng.Offset(0,1).value="-"
End If

<Other codes follow

End if
End Sub


The foregoing works perfectly (as does your cell colouring example).
However, rather than parse the cell c as argument, it appears
intuitively appealing to plump for parsing the worksheet object sh to
the servient subroutine. This option produces:

Sub MainCode2()
Dim sh As Worksheet
Dim c As Range

For each sh in WorkSheets

Call RecalculateRowScore2(sh)

Next
End sub

Sub RecalculateRowScore2(sh as Range) *' Object does not support this
property or method error* on this line
For each c in sh.Range("a:a")
If Instr(sh.rng, "-")=0 Then
sh.rng.Offset(0,1).value=Len(sh.rng)*Asc(Mid(sh.rn g,1,1))
ElseIf Instr(sh.rng, "-")0 Then
sh.rng.Offset(0,1).value="-"
End If

<Other codes follow

End if
End sub


Now the rub: why does EXCEL have a problem treating c any differently
from sh in the above examples?


myles


--
Myles
------------------------------------------------------------------------
Myles's Profile:
http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=496613



 
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
Activating sheets with same name in multiple workbooks Barb Reinhardt Excel Programming 4 July 26th 05 05:19 PM
Looping through Sheets Jim Thomlinson[_3_] Excel Programming 3 September 25th 04 03:48 AM
Looping through Sheets dalejrstwin Excel Programming 0 September 24th 04 06:43 PM
Looping through sheets Eric[_7_] Excel Programming 1 July 24th 03 04:45 PM


All times are GMT +1. The time now is 12:31 PM.

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

About Us

"It's about Microsoft Excel"