Consulting

Results 1 to 6 of 6

Thread: Best use of memory

  1. #1
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location

    Best use of memory

    For best use of memory and speed of macro what is the best coding?

    This:
    [vba]
    Dim lbtarget As MSForms.ListBox
    Dim rngSource As Range
    Set rngSource = Worksheets("Sheet1").Range("A2:C5")
    Set lbtarget = Me.ListBox1
    With lbtarget
    .List = rngSource.Cells.Value
    Set rngSource = Nothing
    Set lbtarget = Nothing
    End With
    [/vba]

    Or this
    [vba]
    Dim rngSource As Range
    Set rngSource = Worksheets("Sheet1").Range("A2:C5")
    With Me.ListBox1
    .List = rngSource.Cells.Value
    Set rngSource = Nothing
    End With
    [/vba]

    Thanks to all for reply.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [vba]ListBox1.List = Worksheets("Sheet1").Range("A2:C5")Value [/vba]

  3. #3
    Whenever we work on VBA, to release memory, it is very important to include before End Sub

    [vba]Set rngSource = Nothing

    Set <variable1> = Nothing

    Set <variableN> = Nothing
    [/vba]

  4. #4
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by Kenneth Hobs
    [vba]ListBox1.List = Worksheets("Sheet1").Range("A2:C5")Value [/vba]
    Thanks Kennet, here my code in your way:
    [vba]
    Set sht = Worksheets("Elenchi")
    cmbPersonale.List = sht.Range("B2:B" & sht.Cells(Rows.Count, 2).End(xlUp).Row).Value
    CmbMacchine.List = sht.Range("D2" & sht.Cells(Rows.Count, 4).End(xlUp).Row).Value
    CmbMateriali.List = sht.Range("H2:I" & sht.Cells(Rows.Count, 8).End(xlUp).Row).Value
    CmbProduzione.List = sht.Range("K2:K" & sht.Cells(Rows.Count, 11).End(xlUp).Row).Value

    Set sht = Nothing[/vba]

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by justdriving
    Whenever we work on VBA, to release memory, it is very important to include before End Sub


    [VBA]Set rngSource = Nothing

    Set <variable1> = Nothing

    Set <variableN> = Nothing
    [/VBA]
    Read post#9 from Matt Curland, who knows a thing or two about garbage collection in VB, in this thread http://bit.ly/Curland
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by xld
    Read post#9 from Matt Curland, who knows a thing or two about garbage collection in VB, in this thread http://bit.ly/Curland
    Interesting article xld,

    thanks for the link

Posting Permissions

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