Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Data from array to sheet

$
0
0

I have an array that plots data to a messagebox, how can I also have that same data on a different sheet?

The data I am working with is a linear cable cut list. It looks at the total cable length and the individual lengths and checks to see how many reels of cable I need for all the separate individual lengths.

Ideally Reel 1 lengths would go in column A and the next reel would be column B, so on and so forth with a blank column in between the different cable types.

Example

    Do While TotCut > 0

        'MinCut is smallest 2nd dimension where 1st dimension is > 0
        Do While TmpStk >= MinCut
            If CutArr(I, 1) <= TmpStk And CutArr(I, 0) > 0 Then

                'Reduce current stock length by cut length
                TmpStk = TmpStk - CutArr(I, 1)

                'Reduce number of current cut by 1
                CutArr(I, 0) = CutArr(I, 0) - 1

                'Store current cut length
                ReDim Preserve DetStk(1, k)
                DetStk(0, k) = TotStk + 1
                DetStk(1, k) = CutArr(I, 1)
                k = k + 1
            Else
                'Move to next cut length
                I = I + 1
            End If

            'Reset MinCut
            AllZero = True
            For j = LBound(CutArr) To UBound(CutArr)
                If CutArr(j, 0) > 0 Then
                    MinCut = CutArr(j, 1)
                    AllZero = False
                End If
            Next j
            'If there are no cut pieces remaining, get out
            If AllZero Then
                Exit Do
            End If
        Loop

        'Reset TmpStk and add one to TotStk
        TmpStk = dStk
        TotStk = TotStk + 1

        'Reset i to row of largest 2nd dimension whose 1st dimension Is Not zero
        For j = UBound(CutArr) To LBound(CutArr) Step -1
            If CutArr(j, 0) <> 0 Then
                I = j
            End If
        Next j

        'Reset TotCut to sum of all 1st dimensions
        TotCut = 0
        For j = LBound(CutArr) To UBound(CutArr)
            TotCut = TotCut + CutArr(j, 0)
        Next j
    Loop

    'Message Box Output
    For k = LBound(DetStk, 2) To UBound(DetStk, 2)
       sMsg = sMsg & DetStk(1, k) & vbTab & vbTab _
            & DetStk(0, k) & vbCrLf
    Next k

I can post the entire code if needed. (238 lines)

Thanks for any help.


Viewing all articles
Browse latest Browse all 88868

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>