Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
2 Label Options - Forms Object vs Control Box Object | Excel Discussion (Misc queries) | |||
Object required??? What object? | Excel Discussion (Misc queries) | |||
Object Variable Not Set Error on Selection object | Excel Worksheet Functions | |||
Object Arrays | Excel Programming | |||
Object Arrays | Excel Programming |