Get stored value from existing item in dictionary

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Get stored value from existing item in dictionary

Post by YasserKhalil »

Hello everyone

I am trying the following code

Code: Select all

Sub Test()
    Dim a, dic As Object, s As String, i As Long, j As Long
   
    a = ThisWorkbook.Worksheets("Sheet1").Range("A1").CurrentRegion.Value
    a = Application.Index(a, Evaluate("ROW(1:" & UBound(a, 1) & ")"), [{3,7,13,14,15,16,17,18,19,20,21}])
    
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = 1

    For i = LBound(a) To UBound(a)
        s = a(i, 1) & vbTab & a(i, 2)
        If Not dic.Exists(s) Then
            dic.Add s, s
           
            For j = LBound(a, 2) To UBound(a, 2)
                If j = 1 Or j = 3 Or j = 6 Or j = 9 Then
                    If i > 1 Then a(i, j) = CLng(Application.WorksheetFunction.WorkDay(CDate(a(i, 1)), IIf(j = 1, 0, Val(j / 3))))
                End If
            Next j
        Else
            'Need Here Some Help
            Stop
        End If
    Next i
    
End Sub

What I need to add in this code is to detect if the item existing in the dictionary or not
If new then some calculations will be done ..on columns M to U
And if it is already exists, there is no need to do the calculations again .. just bring the results from the existing
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78633
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Get stored value from existing item in dictionary

Post by HansV »

As far as I can tell you can simply remove the 'Else' part.
Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: Get stored value from existing item in dictionary

Post by YasserKhalil »

Thanks a lot
Please run the above code and have a look at a(7), you will find it empty as it is already existed before
What I need for a(7) for example [This is a duplicate one] >> So I need to take the results in a(7,3) to a(7,11) from existing item
The exisitng item or the first instance of 20/04/2009 and "N" was in a(6)
So I would like to fill a(7,3) to a(7,11) with the same values in a(6,3) to a(6,11)

Hope it is clear now

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: Get stored value from existing item in dictionary

Post by YasserKhalil »

Posted at this link too
https://www.excelforum.com/excel-progra ... ost5159456" onclick="window.open(this.href);return false;