Trying to use data from Worksheet and Userform for my Dictionary

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Trying to use values from various Worksheet cells , Listbox and Toggle Switch Value for the dictionary
See my attempt below.
The code runs till it gets to this Line
VBA Code:
Set TPodWidth = UsForm.Toolpod_Width
Then jumps over the rest of the code?


VBA Code:
Sub DrNoDict()

        Dim i As Long
        Dim ar As Variant
        Dim wsSource As Worksheet, wsDest As Worksheet
        Dim K As Variant
        Dim TPodWidth As ComboBox
        Dim TPod As ToggleButton
        
        Set TPodWidth = Body_And_Vehicle_Type_Form.Toolpod_Width
        Set TPod = Body_And_Vehicle_Type_Form.Add_Toolpod
        Set wsSource = ThisWorkbook.Worksheets("Drawing No")
        Set wsDest = ThisWorkbook.Worksheets("Job Card Master")
        


If wsDest.Range("B2") = "Ford Transit" And wsDest.Range("D6") = "L2 Single" And TPodWidth = 600 And TPod.Value = False Then

ar = [A1].CurrentRegion

With CreateObject("Scripting.Dictionary")
    For i = 6 To UBound(ar)
      .Item(ar(i, 4)) = .Item(ar(i, 4))
    Next i
    
    For Each K In .Keys
    Debug.Print K
    Next K

        
        
        End With
        End If
        
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 Toolpod is a combobox control on a userform called Body_And_Vehicle_Type_Form then there are 2 problems with your code.
firstly the width of the control is
Body_And_Vehicle_Type_Form.Toolpod.Width
and secondly you cannot assign a numeric value as a Combobox (as delcared in your Dim)
 
Upvote 0
I decided to create a proper dictionary see below.
Not sure how to get values from it to make the code work with my choices on the
VBA Code:
If wsDest.Range("B2") = "Ford Transit" And wsDest.Range("D6") = "L2 Single" And TPodWidth = 600 And TPod.Value = False Then
Line

The Dictionary seems to fail on the
VBA Code:
DrNo.DrNo1ID = rng.Offset(0, 1).Value
Line

If finds the right Values but shows up a error "Object variable or with block variable not set"

VBA Code:
Public Drawing_Dictionary As New Dictionary
Sub DrNosDict()

        Dim rng As Range
        Dim DrNo As Object
        Dim wsSource As Worksheet
        Dim wsDest As Worksheet
        Dim TPodWidth As ComboBox
        Dim TPod As ToggleButton
        Dim i As Integer
        
        
        Set TPodWidth = Body_And_Vehicle_Type_Form.Toolpod_Width
        Set TPod = Body_And_Vehicle_Type_Form.Add_Toolpod
        
        Set wsSource = ThisWorkbook.Worksheets("Drawing No")
        Set wsDest = ThisWorkbook.Worksheets("Job Card Master")

        Set Drawing_Dictionary = New Dictionary
        Set DrNo = DrNo

wsSource.Select

For Each rng In Range("C6", Range("C6").End(xlDown))
     Set DrNo = DrNo
     
    
     DrNo.PartsID = rng.Value
     DrNo.DrNo1ID = rng.Offset(0, 1).Value
     DrNo.DrNo2ID = rng.Offset(0, 2).Value
     DrNo.DrNo3ID = rng.Offset(0, 3).Value
     DrNo.DrNo4ID = rng.Offset(0, 4).Value
     DrNo.DrNo5ID = rng.Offset(0, 5).Value
     DrNo.DrNo6ID = rng.Offset(0, 6).Value
     DrNo.DrNo7ID = rng.Offset(0, 7).Value
     DrNo.DrNo8ID = rng.Offset(0, 8).Value
     DrNo.DrNo9ID = rng.Offset(0, 9).Value
     
     Drawing_Dictionary.Add DrNo.DrNo1ID, DrNo
      Drawing_Dictionary.Add DrNo.DrNo2ID, DrNo
       Drawing_Dictionary.Add DrNo.DrNo3ID, DrNo
        Drawing_Dictionary.Add DrNo.DrNo4ID, DrNo
         Drawing_Dictionary.Add DrNo.DrNo5ID, DrNo
          Drawing_Dictionary.Add DrNo.DrNo6ID, DrNo
           Drawing_Dictionary.Add DrNo.DrNo7ID, DrNo
            Drawing_Dictionary.Add DrNo.DrNo8ID, DrNo
             Drawing_Dictionary.Add DrNo.DrNo9ID, DrNo
     
      Set DrNo = Nothing
     Next rng
     
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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