Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Object Arrays

I didn't take the time to get my head around exactly what the code is
doing, but you might want to consider something like:

Sub testab2001()
Dim arr() As Object, i As Integer
ReDim arr(1 To 3)
For i = 1 To 3
Set arr(i) = Worksheets(i)
Next
arr(2).Select '<---selects the second worksheet
End Sub

It has been suggested to me that Collections should always be used
rather than arrays of Objects; I don't know enough about it to express a
view.

Alan Beban

Paul wrote:
Hello,

I may just be beating up the wrong tree here but I'll
never know without asking.

I have a series of workbooks that code is used to extract
matching entries according to a selected criteria. My
problem is that I declare the variables as Objects, and
reference them in an array so I can use the index
funcation to cycle through them.

What I have found is that the array dim as variant,
returns the text string of the object not the reference
to it.

So what I would like to be able to do is to cycle through
the objects (whether Workbooks, Worksheets or Ranges).
Following is an exerpt from the code....
----------------------------------------------------------
Sub GenerateReportMain()
On Error Resume Next
Dim wb0, wb1, wb2, wb3, ActWB As Workbook
Dim i As Range
Dim wb1ActRange As Variant
Dim wb2ActRange As Variant
Dim wb3ActRange As Variant
Dim wbActiveRange As String
Dim wbActRange As Variant
Dim ActiveWB As Variant
Dim WorkSheetNames As Variant
Dim ProgramShort As Variant
Dim ProgGroupIndex As Integer
WorkSheetNames = Array

'Progress Bar Dimensions
Dim Counter As Integer
Dim PctDone As Single
Dim wb1Calcs As Integer
Dim wb2Calcs As Integer
Dim wb3Calcs As Integer
Dim TotalCalcs As Integer

WorkSheetNames = Array
("Training_Main", "Symposiums_Main", "MajorEvents_Main")
wbActRange = Array(wb1ActRange, wb2ActRange, wb3ActRange)
ProgramShort = Array("t", "s", "m")
ActiveWB = Array(wb1, wb2, wb3)
Counter = 1
TotalCalcs = 0
ProgGoupIndex = 1
While ProgGroupIndex < 4
' Used to Cycle through the code to advance wb1, wb2,
wb3... And other Array Arguments.

ActWb = ActiveWB (ProgGroupIndex)
ActWS = ActiveWS (ProgGroupIndex)
ActRange = ActiveRange(ProgGroupIndex)
ProgShort = ProgramShort(ProgGroupIndex)


For Each i In ActWB.Worksheets(ActWS).Range(ActRange)
If Rows(i.Row).Row 2 And Rows(i.Row).Row <
ActWB.Worksheets(ActWS).UsedRange.Rows.Count Then
.......Processs Code..........

next i
ProgGroupIndex = ProgGroupIndex + 1
wend
end sub
----------------------------------------------------------

At the moment, I have to repeat about 120 Lines of code
three times to complete the import, so If i can cycle
through the variables then that would make my job a lot
easier.

Thanks.


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
2 Label Options - Forms Object vs Control Box Object Awrex Excel Discussion (Misc queries) 3 July 17th 09 07:10 PM
Object required??? What object? jlclyde Excel Discussion (Misc queries) 8 November 1st 08 12:21 AM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Object Arrays Bob Kilmer Excel Programming 0 July 23rd 03 03:00 AM
Object Arrays Bob Kilmer Excel Programming 1 July 23rd 03 02:53 AM


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

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"