Results 1 to 3 of 3

Help cleaning code, and dynamic arrays

Threaded View

  1. #1
    Registered User
    Join Date
    12-10-2015
    Location
    Aarhus, Denmark
    MS-Off Ver
    2016
    Posts
    22

    Help cleaning code, and dynamic arrays

    I am complete rookie to VBA, but i have been attempting to write a macro that can generate a list of productions ID's that are fit for production, based on two parameters. A production can only be initiated if it can be produced 100%, no split production is allowed, and the current stock of the part to be produced need to be less than 20% of a years sales.

    I have written the following code, which does do what i want it to, but i know it can be written smarter, and with dynamic arrays, cause i never know the excact amount of produciton orders to look through, and how many can be singled out for production.

    Sub LavProduktionsListe()
    
       Dim lngProduktionsID(1 To 125) As Long             'ProduktionsID variabel array
       Dim curProducerbar(1 To 125) As Currency          ' Producerbar variabel array
       Dim curStockPct(1 To 125) As Currency         ' Lager procent variabel array
       Dim i As Long                                     ' Row count
      
       i = 1
       
       With Sheets("Oversigt")
          Application.ScreenUpdating = False
          Do Until IsEmpty(.Cells(i + 1, 1)) = True
             lngProduktionsID(i) = .Cells(i + 1, 1).Value
             curProducerbar(i) = .Cells(i + 1, 4).Value
             curStockPct(i) = .Cells(i + 1, 6).Value
             If curProducerbar(i) = 1 And curStockPct(i) < 0.2 Then      'If it is possible to produce 100% of a produciton order, and current stock is less than 20% of 12 months sales
                Range("I2500").Select
                Selection.End(xlUp).Select
                ActiveCell.Offset(1, 0).Range("A1").Select               'Select first empty cell in column I
                ActiveCell = lngProduktionsID(i)                         ' Write production ID
             End If
             i = i + 1                                    'Next row
          Loop
             Application.ScreenUpdating = True
       End With
    End Sub
    I have attached a sample sheet of how my excel sheet with production overview looks like. Can someone help me rewrite the code to use dynamic arrays? And please make comments as to what is what and so on, so I can learn. Useful articles and guides to dynamic arrays are also more than welcome to be shared, so can nail this VBA programming eventually.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help cleaning up code.
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2015, 10:59 AM
  2. Looking for help Cleaning up code
    By SmoothRider in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2014, 02:58 PM
  3. [SOLVED] Need help cleaning up my code...
    By pasqualebaldi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2014, 12:30 PM
  4. [SOLVED] Help with cleaning up code ?
    By james 35 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2013, 06:05 AM
  5. Cleaning up this code
    By toaksie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2012, 05:50 PM
  6. Code needs cleaning up
    By hambone in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2010, 10:51 AM
  7. Help Cleaning up Code
    By Lost and Looking for Help in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2006, 09:30 AM

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