Results 1 to 23 of 23

VBA Code Using Arrays To Be Optimized

Threaded View

  1. #1
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,876

    VBA Code Using Arrays To Be Optimized

    Hi,

    On the attached file, when a Value from Cell D1 is selected, it outputs corresponding values from Column E separated by commas..

    All working as desired with this code -

    Sub Conc()
    
        Dim InputVal As String, R As Variant, Counter As Integer, NewVal(), C As Integer
    
        InputVal = Range("D1").Value2
    
        R = Range("A1").CurrentRegion
    
        For Counter = LBound(R,1) To UBound(R,1)
            If R(Counter, 1) = InputVal Then
                C = C + 1
                ReDim Preserve NewVal(1 To C)
                NewVal(C) = R(Counter, 2)
            End If
        Next Counter
    
        Range("E1").Value2 = InputVal & " " & Join(NewVal, ",")
    
    End Sub
    I would like to know If the code can be further optimized? For example better use of arrays, loops etc.
    Attached Files Attached Files
    Last edited by NeedForExcel; 07-22-2015 at 02:04 AM.
    Cheers!
    Deep Dave

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Shorten Code with arrays
    By CraigsWorld in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2015, 01:45 PM
  2. Curious about a more optimized method
    By cman0 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-24-2014, 07:40 PM
  3. Optimized Product Selection Problem
    By Atticus_Finch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2013, 09:33 AM
  4. Create an Optimized Schedule (Warning: A lot of reading!)
    By BYizz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2013, 02:48 PM
  5. Optimized cutting length help needed
    By mr63249 in forum Excel General
    Replies: 2
    Last Post: 05-31-2013, 08:06 AM
  6. [SOLVED] Very inefficient code because of different sizes of arrays, how do i shorten my code?
    By Brammer88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 04:49 PM
  7. Working Code: Can it be optimized?
    By qcity in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 06-17-2011, 01:00 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