Building and Comparing a Multidimensional Array in a for loop

Learner99

New Member
Joined
Apr 7, 2014
Messages
21
Hi everyone, I'm trying to build to 2 mulitimensional arrays to compare against each other.
When it finds matchs it will output the contents of the array.
The fields I want to put in the first array are "Shedule_P" and "Shedule_D" they both have the same number of rows.
The second array should hold "Sheet_P" and "Sheet_D". They also have the same number of rows for those 2 variables.
The loop would be the first instance of "Shedule_P" and "Shedule_D" would go against "Sheet_P" and "Sheet_D"
Then "Sheet_P" and "Sheet_D" would incriment and check again.
Once the "sheet" Array hits the end the the "Schedule variable would incriment and the process would repeat.
Any help would be greatly appreciated.
Thanks

Code:
Sub CopyJobs()
'
'This will copy the Job Name to the correct cell
'
Dim f_slash As Long
Dim Sec_slash As Long
Dim colin As Long
Dim StartDate As Long
Dim EndDate As Long
Dim Shedule_D As Date
Dim Shedule_P As String
Dim Sheet1Date As Date
Dim Sheet1Press As String
'===================================================================
Range("J1").Select   ' Gets the Date from  Report
                     
' Get start position of the date
colin = InStr(1, ActiveCell, ",")               'first ":" in the cell
f_slash = InStr(1, ActiveCell, "/")             'first "/" in the cell
StartDate = f_slash - (f_slash - colin - 1)     'get the start position subtract the two
' Get the length
Sec_slash = InStr(f_slash + 1, ActiveCell, "/") + 4 'second "/" in the cell
EndDate = Sec_slash - StartDate + 1                 'get the length start pos minus the end
' Mid command to isolate the date
Shedule_D = Mid(ActiveCell, StartDate, EndDate)
'===================================================================
' Gets the Press from Schedule Report
Shedule_P = Mid(Range("A1").Select, 1, 7)
'===================================================================
' Get the Date and Press from Sheet1
Sheet1_D = Sheets("Sheet1").Range("B1")    ' Gets Date from sheets 1 (starts Here)
Sheet1_P = Sheets("Sheet1").Range("A3")    ' Gets Press from sheets 1 (starts Here)
'===================================================================
'*** Everything works to this point***
'===================================================================
'Building arrays from Report Page
Dim RowInfo() As Variant
Dim cnt01 As Long
Dim cnt02 As Long
Dim r As Range
Dim n As Long
    Range("A1").Select
    Selection.End(xlDown).Select
    Set r = Range("A1:" & Selection.Address)    'This is where you set the column to sort on
    For n = 1 To r.Rows.Count
          For n = 1 To r.Rows.Count                        
            ReDim Preserve RowInfo(cnt01,cnt02)             'Make RowInfo dynamic.
            RowInfo(cnt01, cnt02) = (Shedule_P ^ Shedule_D)
          Next n
    Next n

   For n = 1 To r.Rows.Count
                For n = 1 To r.Rows.Count
                    Debug.Print RowInfo(cnt01, cnt02)
                Next n
   Next n

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If this helps. Here is what I was looking to do.
I have a 2 tab excel sheet. On sheet1 I have a raw list of data like so.
Example:
Column A, Column B, Column C,
Id codes, job info, Dates,
111, job info a, 4-10-2014,
111, job info b, 4-11-2014,
111, job info c, 4-15-2014,
222, job info d, 4-10-2014,
222, job info e, 4-11-2014,
Ect…

On sheet2 I have the following.
Column A, Column B, Column C,
Id codes without repeats, Date starting today, Next Days Date,
Blank Cell, 4/10/2014, 4/11/2014, etc…
111,
222,
333,
ect…

So what I’m trying to do is..
1) Pull in all the id codes on sheet1 with the dates
2) On sheet2 match the id code and date and place the job info in that cell

Example:
Column A , Column B, Column C,
Id codes without repeats, Date starting today, Next Days Date,
Blank Cell, 4/10/2014, 4/11/2014, etc…
111, job info a, job info b,
222, job info d, job info e,
333,

Hopefully that makes sense
 
Upvote 0
I found the answer to the above issue for those that may be watching this thread.
The person who came up with this was amazing.
Code:
Function ftnLastRow(WSName As String, aCol As Long) As Long
With Worksheets(WSName)
    ftnLastRow = .Cells(.Rows.Count, aCol).End(xlUp).Row
End With
End Function
Sub MatchRecords()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim a As Long
Dim c As Range
Dim aCol As Long
Dim lr As Long
Dim LR1 As Long
Dim LR2 As Long
Dim firstAddress As String
Set WS1 = Worksheets("Finishing Schedule Report")
Set WS2 = Worksheets("Sheet1")
LR1 = ftnLastRow(WS1.Name, 1)          ' get last row from each sheet from the above funtion
LR2 = ftnLastRow(WS2.Name, 1)
With WS2                               ' Sheet 1
    For a = 1 To LR1                   ' Finishing Schedule Report starts on Cell A1
        With .Range("A1:A" & LR2)      ' Goes to cell A1 on FinishingReport to get range
            Set c = .Find(WS1.Cells(a, 1), LookIn:=xlValues)
            If Not c Is Nothing Then
                firstAddress = c.Address
                Do
                    On Error Resume Next
                    aCol = Application.WorksheetFunction.Match(WS1.Cells(a, 3), WS2.Rows(1), 0) 'sheet 1 row thats being check against
                    On Error GoTo 0
                    If aCol <> 0 Then
                        WS2.Cells(c.Row, aCol) = WS1.Range("B" & a)   'copies in text in colum B fromfin to sheet 1
                    End If
                    aCol = 0
                Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstAddress
                
            End If
        End With
    Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,923
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top