Consulting

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 21 to 40 of 45

Thread: Python dictionary in VBA

  1. #21
    If it's not too much trouble.
    Could you describe step by step, how to do it.
    Because my excel doesn't let to run your macro file
    Thanks!

  2. #22
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    what version of excel do you have?

  3. #23
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    i resave the file to 97-2003 format
    Attached Files Attached Files

  4. #24
    Sry, my bad. It opened

  5. #25
    On thing happened!
    When I added some more rebars to Dictionary, it gave me error, because there is already with same key word element
    For ex.
     ' 1 rebars
        rebars.Add 0.28, "1x6"
        rebars.Add 0.5, "1x8"
        rebars.Add 0.79, "1x10"
        rebars.Add 1.13, "1x12"
        rebars.Add 1.54, "1x14"
        rebars.Add 2.01, "1x16"
        rebars.Add 2.54, "1x18"
        rebars.Add 3.14, "1x20"
        rebars.Add 3.8, "1x22"
        rebars.Add 4.91, "1x25"
        rebars.Add 6.16, "1x28"
        rebars.Add 8.04, "1x32"
        rebars.Add 10.18, "1x36"
        rebars.Add 12.57, "1x40"
        
        ' 4 rebars
        rebars.Add 1.13, "4x6"
        rebars.Add 2.01, "4x8"
        rebars.Add 3.14, "4x10"
        rebars.Add 4.52, "4x12"
        rebars.Add 6.16, "4x14"
        rebars.Add 8.04, "4x16"
        rebars.Add 10.18, "4x18"
        rebars.Add 12.57, "4x20"
        rebars.Add 15.21, "4x22"
        rebars.Add 19.63, "4x25"
        rebars.Add 24.63, "4x28"
        rebars.Add 32.17, "4x32"
        rebars.Add 40.72, "4x36"
        rebars.Add 50.27, "4x40"
    How could i fix it in VBA? Perhaps i have to use extra dictionary, ex. rebars2?
    Last edited by Einsener37; 03-15-2023 at 03:56 AM.

  6. #26
    Okei i did it as i did in Python
    I used String type for key word and I added 0 to the end, example 3.140 and converted string to long so i could compare
    But it doesn't help.
    I use function CLng, and i rounds it as it wishes and my if statements won't work anymore
    Last edited by Einsener37; 03-15-2023 at 04:47 AM.

  7. #27
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    Perhaps use the '4x28' as the key as they are unique and the numbers as the items?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #28
    Quote Originally Posted by p45cal View Post
    Perhaps use the '4x28' as the key as they are unique and the numbers as the items?
    Muchos grazies, that might work

  9. #29
    Quote Originally Posted by JKwan View Post
    here you go. I did not use a form, I just put a control onto the sheet
    Could you help me more.
    If you run your macro and enter the value, which is already in rebars dictionary , ex 1.57. Then it will give such error
    How should code be changed for not to get such error massage?
    Thanks!
    error2.jpg

  10. #30
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    See attached.
    BTW:
    2023-03-17_094356.jpg
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  11. #31
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,050
    Location
    Since this thread is apparently not solved I shall remove the "Solved" entitlement
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  12. #32
    Quote Originally Posted by p45cal View Post
    See attached.
    BTW:
    2023-03-17_094356.jpg
    Thank you!
    It works

  13. #33
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,050
    Location
    Then mark the thread as solved Einsener 37.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  14. #34
    Quote Originally Posted by p45cal View Post
    See attached.
    BTW:
    2023-03-17_094356.jpg
    Could you help me to modify it a bit.
    How does it work with VBA if i want to split the result into different sells? Ex, cross-area, pcs and diameter in different cells.
    Capture.jpg

  15. #35
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    Attached.
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  16. #36
    Just to understand more
    Where have you defined these variables xx, yy, zz?
    Capture2.jpg
    Attached Images Attached Images

  17. #37
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    I haven't.
    I took out Option Explicit.
    If you must define them:
    Dim xx,yy,zz
    in the same Listbox_Click sub.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  18. #38
    Quote Originally Posted by p45cal View Post
    I haven't.
    I took out Option Explicit.
    If you must define them:
    Dim xx,yy,zz
    in the same Listbox_Click sub.
    Much appreciated

  19. #39
    Quote Originally Posted by p45cal View Post
    I haven't.
    I took out Option Explicit.
    If you must define them:
    Dim xx,yy,zz
    in the same Listbox_Click sub.
    I would like to add one listbox with just opportunity to choose rebar
    What am I doing wrong in code, that it gives me error
    Public Sub UserChoice()
    Dim WS As Worksheet
        Dim lb2 As MSForms.ListBox
        Set WS = ThisWorkbook.Worksheets("Sheet1")
        Set lb2 = WS.OLEObjects("ListBox2").Object
        lb2.Clear
        WS.Range("E20").Resize(, 6).ClearContents
        Dim rebars2 As Scripting.Dictionary
        Set rebars2 = New Scripting.Dictionary
       
        ' 2 rebars
        rebars2.Add "2x6", 0.57
        rebars2.Add "2x8", 1.01
        rebars2.Add "2x10", 1.57
        rebars2.Add "2x12", 2.26
        rebars2.Add "2x14", 3.08
        rebars2.Add "2x16", 4.02
        rebars2.Add "2x18", 5.09
        rebars2.Add "2x20", 6.28
        rebars2.Add "2x22", 7.6
        rebars2.Add "2x25", 9.82
        rebars2.Add "2x28", 12.32
        rebars2.Add "2x32", 16.08
        rebars2.Add "2x36", 20.36
        rebars2.Add "2x40", 25.13
        
        
        
        For i = 0 To rebars2.Count - 1
            lb2.AddItem rebars2.Items(i) & " - " & rebars2.Keys(i)
            
        Next i
        
        
    
    
    
    
    End Sub
    error3.jpg

  20. #40
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    Make it easy for us to help you, supply a workbook with where you've got to so far.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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