Results 1 to 3 of 3

Thread: How to condense several rows into fewer rows?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Or a UDF to do the trick....

    Code:
    Function Condensor(rngSourceRange As Variant, lngFragments As Long, lngIndex As Long) As Variant
    
        Dim lng As Long
        Dim sngSegment As Single
        Dim varSourceRange As Variant
        Dim sngFraction As Single
        Dim sngDivisions As Long
        Dim varIntermediate As Variant
        Dim sngCounter As Single
        Dim lngCounter As Long
        
        On Error GoTo ErrH
        varSourceRange = Application.Transpose(rngSourceRange)
        lng = UBound(varSourceRange)
        sngSegment = lng / lngFragments
        If Int(sngSegment) = sngSegment Then
            For lng = 1 + (sngSegment * (lngIndex - 1)) To sngSegment * lngIndex
                Condensor = Condensor + varSourceRange(lng)
            Next lng
        Else
            sngFraction = Abs(Int(sngSegment) - sngSegment)
            sngDivisions = 1 / sngFraction
            ReDim varIntermediate(1 To lng * sngDivisions)
            For lng = 1 To lng * sngDivisions
                If sngCounter < sngDivisions Then
                sngCounter = sngCounter + 1
                varIntermediate(lng) = varSourceRange(lngCounter + 1) / sngDivisions
                Else
                    lngCounter = lngCounter + 1
                    sngCounter = 1
                    varIntermediate(lng) = varSourceRange(lngCounter + 1) / sngDivisions
                End If
            Next lng
            For lng = 1 + ((sngSegment / Abs(Int(sngSegment) - sngSegment)) * (lngIndex - 1)) To Int((sngSegment / Abs(Int(sngSegment) - sngSegment)) * lngIndex)
                Condensor = Condensor + varIntermediate(lng)
            Next lng
        End If
        Exit Function
    ErrH: Condensor = ""
        
    End Function
    Check attached workbook for reference
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Delete Rows
    By ayazgreat in forum Excel Help
    Replies: 2
    Last Post: 12-13-2012, 11:48 AM
  2. Transpose data into Rows
    By vikash200418 in forum Excel Help
    Replies: 2
    Last Post: 04-10-2012, 11:02 PM
  3. Replies: 2
    Last Post: 05-06-2011, 02:59 AM
  4. Delete Empty Rows
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 04-28-2011, 02:13 AM
  5. Deleting blank rows
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-14-2011, 03:14 AM

Tags for this Thread

Posting Permissions

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