• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using a similar technique to the index function in vba

CLoos

New Member
I can't seem to get started on this macro, maybe someone can give me a hint. What I want to do is when the user pushes the "schedule" button on the input sheet the macro will loop through a series of dates and values (from sheet3) and place the values onto the schedule worksheet. To do that the macro will need to identify the corresponding date and plant on the schedule sheet. So I am not sure how to do that. Do I set up a range of variables?

Thanks for any advice. No code written but worksheet attached.
 

Attachments

  • Schedule.xlsm
    75.5 KB · Views: 12
I simply want to transfer the data from sheet3 to the schedule sheet using two variables as values
 
Try
Code:
Sub test()
    Dim a, i As Long, ii As Long, dic As Object
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = 1
    a = Sheets("sheet3").Cells(1).CurrentRegion.Value
    For ii = 1 To UBound(a, 2) Step 2
        Set dic(a(1, ii)) = CreateObject("Scripting.Dictionary")
        For i = 2 To UBound(a, 1)
            dic(a(1, ii))(a(i, ii)) = a(i, ii + 1)
    Next i, ii
    With Sheets("Schedule").Cells(1).CurrentRegion
        .Offset(1, 1).ClearContents: a = .Value
        For i = 2 To UBound(a, 1)
            If dic.exists(a(i, 1)) Then
                For ii = 2 To UBound(a, 2)
                    If dic(a(i, 1)).exists(a(1, ii)) Then a(i, ii) = dic(a(i, 1))(a(1, ii))
                Next
            End If
        Next
        .Value = a
    End With
End Sub
 
Thank you! I can work with this! I won't be able to test it until next week but I am sure it will work. I have never used the create object (scripting.dictionary) before, it is a bit over my head but I am anxious to learn this. Again Thanks!
 
Back
Top