0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VBA_04_Dictionary_Exists_Worksheet_Cells_Sample

Posted at

Keyword

Dictionary
Exists
Worksheet
Cells

Sample Code

20220526
Public Sub MySample20220526()

    Dim mySheet As Worksheet
    Dim myDicList As New Dictionary
    Dim i As Long
    Dim myStrFileName As String: Dim myStrFileSize As String
    Dim myStrKeyword1 As String: Dim myStrKeyword2 As String
    
    myStrKeyword1 = "SecretNote.xlsx"
    myStrKeyword2 = "DeathNote.xlsx"
    
    Set mySheet = ThisWorkbook.ActiveSheet
    
    For i = 3 To 14
        
        With mySheet
            myStrFileName = .Cells(i, "C").Value
            myStrFileSize = .Cells(i, "E").Value
        End With
        
        If Not myDicList.Exists(myStrFileName) Then
            myDicList.Add myStrFileName, myStrFileSize
            
        End If
        
    Next i
    
    If myDicList.Exists(myStrKeyword1) Then
        MsgBox myStrKeyword1 & vbCrLf & _
                myDicList.Item(myStrKeyword1)
    End If
    
    If Not myDicList.Exists(myStrKeyword2) Then
        MsgBox myStrKeyword2 & "は存在しません"
    End If

End Sub

Sample Data

無題4.jpg

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?