Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Passing var types, groups and properties to a sub

Tom, I am considering calling this For Each loop several
times(7-10 times). The order in which I call it will vary
as well. That is, it may contain cells or comments but in
varying orders. Is it possible to write this code with
only one call statement instead of the two you have
suggested.

Thanks


-----Original Message-----
Sub EFGH()
Dim cmt As Comments
Dim cell As Range
Call ForEachLoop(ActiveSheet.UsedRange)
Call ForEachLoop(ActiveSheet.Comments)
End Sub


Sub ForEachLoop(coll As Object)
Dim itm As Object
For Each itm In coll
If TypeName(itm) = "Range" Then
' special code for range
ElseIf TypeName(itm) = "Comment" Then
' special code for comment
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote

in message
...
I have a routine which checks cells and comments in a
spreadsheet. I have written the routine using two
separate For Each loops. However I would like to

optimize
the code so that only one loop exists and it always

knows
whether what element (type of variable) it is ( in this
case a comment("cmt") or a range ("Range")). I may also
have to pass the both the group (i.e. sh )and the group
property to a variable as well (i.e. .UsedRange
and .Comments)

I am guessing that I can either make the variables cmt

or
cell Public so that I do not have to pass them to the
routine. Or I can pass them with some additional
information telling the sub what type of variable they
are. I am assuming I can use the TypeName function to
return the variable type. But how do you pass this to a
sub when calling it. Don't know how to pass group or
properties of group to a sub.

See original code below with incomplete suggestion for

new
code

Original Code

Dim cmt As Comment
Dim cell As Range

For Each cell In sh.UsedRange

Next

For Each cmt In sh.Comments

Next
End Sub

New code
Dim cmt As Comment
Dim cell As Range


Call ForEachLoop (??????)


End Sub



.

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
How can I hide unused file types from file types list in save dial Estra Q Excel Discussion (Misc queries) 1 December 17th 09 12:36 PM
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
Formulas using the same data types but with varying size groups MAC253 Excel Discussion (Misc queries) 0 October 3rd 06 04:31 PM
passing Excel system values (constant) of properties as arguments Roland Excel Programming 3 January 14th 05 10:06 PM
Passing properties to a procedure Matt McQueen[_2_] Excel Programming 1 July 30th 03 04:44 PM


All times are GMT +1. The time now is 11:45 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"