Results 1 to 2 of 2

vba dictionary

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-08-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    157

    vba dictionary

    Similar to the problem I had earlier, I'm trying to get to read my dictionary from a different workbook.

       Dim rCl As Range  'analysis range
        Dim dic
        
        Set dic = CreateObject("scripting.dictionary")
        With Worksheets("Sheet3")
        '1 refers to Column A which is Analysis's
        For Each rCl In .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp))
            If Not dic.exists(CStr(rCl)) Then dic.Add CStr(rCl), rCl.Row
        Next rCl
        End With
        cboAnalysis.List = dic.keys
        'clears current drop down value to clear
        cboAnalysis.Value = ""
    currently reads from current workbook sheet 3 I'm running off, Im trying to get it to read off a different workbook

    I'm trying to get it to work in the similar way this works:

    Private Sub cmd_Request_Click()
    On Error GoTo ErrorHandler
        
    Dim RowNo As Long
    Dim Id As String
    
        
    Application.ScreenUpdating = False ' turn off the screen updating
    'Enter Workbook names and Sheet names.
    Set Wb = Workbooks.Open("S:\Information\Design Systems Engineering\CFD Methods\KG\Work Associated\KG\Projects\HPC Booking\Final Documents\Final Prep Folders\regularUsers.xls", True, True)
    Set Ws = Worksheets("Sheet1")
    Id = Me.txt_Request
        
    RowNo = Application.WorksheetFunction.Match(Id, Ws.Range("A1:A999"), 0)
        
    Me.txtName = Ws.Cells(RowNo, 2)
    Me.txtPhone = Ws.Cells(RowNo, 3)
    Me.txtDepartment = Ws.Cells(RowNo, 4)
    Me.txtID = Ws.Cells(RowNo, 1)
        
    CleanExit:
    Wb.Close False ' close the source workbook without saving any changes
    Set Wb = Nothing ' free memory
    Application.ScreenUpdating = True ' turn on the screen updating
    Exit Sub
    
    ErrorHandler:
    MsgBox "Unable to match ID, enter valid ID.", vbOKOnly
    GoTo CleanExit
        
    End Sub
    where it reads from a different workbook with and the screen updating goes on and off etc.

    Any help appreciated

    K
    Last edited by kieranbop; 10-20-2011 at 06:18 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1