Results 1 to 10 of 193

Thread: Appendix Thread 2. ( Codes for other Threads, HTML Tables, etc.)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Code for suppot of this Thread:
    http://eileenslounge.com/viewtopic.php?f=30&t=31540

    Code:
    Sub SpltTests()
     Call Splt(1, 244, 1377, 1620)
    End Sub
    Function Splt(ByVal N1a As Long, ByVal N1b As Long, ByVal N2a As Long, ByVal N2b As Long) As Variant ' Variant as I don't know yet what might be wanted as output
    Rem 1 full columns of data - full data arrays
    Dim Clm1() As Variant: Let Clm1() = Evaluate("=row(" & N1a & ":" & N1b & ")")  ' This returns a one "column" 2 Dimensional array of all the numbers between N a and N b
    Dim Clm2() As Variant: Let Clm2() = Evaluate("=row(" & N2a & ":" & N2b & ")")
    Rem 2 get total number of arrays needed
    Dim En As Long ' We want
     Let En = Int(((N1b - N1a) + 1) / 40) + 1
    Rem 3a Not so simple maths to get some grouped numbers for top left of output arrays
    ' I need rows 1,1,1,42,42,42,83, columns 1,4,7,1,4,7,1
    Dim ltrEn As String: Let ltrEn = Cltr(En) ' column letter from column number - G in example data
    Dim ltrEnPlus3 As String: Let ltrEnPlus3 = Cltr(En + 3)
    Dim Rws() As Variant ' row co ordinates of outout arrays
     Let Rws() = Evaluate("=Index((int((column(D:" & ltrEnPlus3 & ")-1)/3)),)") ' Evaluate("=Index((int((column(D:J)-1)/3)),)") 'returns {1, 1, 1, 2, 2, 2, 3}
    Dim Clms() As Variant ' column co ordinates of output arrays
     Let Clms() = Evaluate("=Index((mod(column(A:" & ltrEn & ")-1,3)+1),)") ' Evaluate("=Index((mod(column(A:G)-1,3)+1),)") 'Returns { 1, 2, 3, 1,  2, 3, 1 }
    Dim Cnt '  Loop for all data sections ==================================================
        For Cnt = 1 To En
        Rem 3b Top left for each array
        Dim rTL As Long, cTL As Long
         Let rTL = ((Rws(Cnt) - 1) * 41) + 1 ' In the looping this will give 1,1,1,42,42,42,83
         Let cTL = ((Clms(Cnt) - 1) * 3) + 1 ' In the looping this will give 1,4,7,1,4,7,1
        Rem 4 Columns of data for each loop
        Dim ClmOut1() As Variant, ClmOut2() As Variant '4a) use Index with arrays to get part of the sections from full data arrays
         Let ClmOut1() = Application.Index(Clm1(), Evaluate("=column(" & Cltr(((Cnt - 1) * 40) + 1) & ":" & Cltr(Cnt * 40) & ")"), 0) ' column 1
         Let ClmOut2() = Application.Index(Clm2(), Evaluate("=column(" & Cltr(((Cnt - 1) * 40) + 1) & ":" & Cltr(Cnt * 40) & ")"), 0) ' column 2
        Dim ClmOut1_1(1 To 40, 1 To 1) As Variant, ClmOut2_1(1 To 40, 1 To 1) As Variant ' I need Variant so as to get empty back for last array in loop paste out
        Dim Cnt2 As Long '4b) Loop to get convenient for output   2 dimensional 1 column arrays
            For Cnt2 = 1 To 40
                If IsError(ClmOut1(Cnt2)) Then Exit For ' To stop filling last array for large than top range value
             Let ClmOut1_1(Cnt2, 1) = ClmOut1(Cnt2) ' column 1
             Let ClmOut2_1(Cnt2, 1) = ClmOut2(Cnt2) ' column 2
            Next Cnt2
        Rem 5 Output of arrays to worksheet
        '5a Title
        Dim Tital(1 To 1, 1 To 2) As String: Let Tital(1, 1) = "S1": Let Tital(1, 2) = "S2"
        '5b Columns of data
        Dim WsRes As Worksheet: Set WsRes = Worksheets("Result")
         WsRes.Cells.Item(rTL, cTL).Resize(1, 2).Value = Tital() ' Title
         WsRes.Cells.Item(rTL + 1, cTL).Resize(40, 1).Value = ClmOut1_1() ' column 1
         WsRes.Cells.Item(rTL + 1, cTL + 1).Resize(40, 1).Value = ClmOut2_1() 'column 2
         Erase ClmOut1_1(), ClmOut2_1() ' without doing this out last array will not have any empties in it
        Next Cnt ' =============================================================================
    End Function
    
    ' Column letter  http://www.excelforum.com/development-testing-forum/1101544-thread-post-appendix-no-reply-needed-please-do-not-delete-thanks-4.html#post4213980
    Function Cltr(ByVal lclm As Long) As String 'Using chr function and Do while loop      For example http://www.excelforum.com/excel-programming-vba-macros/796472-how-to-go-from-column-number-to-column-letter.html
        Do
         Let Cltr = Chr(65 + (((lclm - 1) Mod 26))) & Cltr
         Let lclm = (lclm - (1)) \ 26 'This gives the number of 26's ( if any ), but just the excact part, in the next number down , - so applying the rest formula to this new number will again leave a difference "left over" rest.
        Loop While lclm > 0 'Only loop further if number was big enough to still have 0-25's in it
    End Function
    'Dim arr1_40() As Variant: Let arr1_40() = Evaluate("=column(A:AN)") ' {1, 2, 3 ....40}
    _.__________________________

    It will take numbers like 1, 244, 1377, 1620 and then give your wanted result (I think, like Hans said, your test data is a bit wrong – check your row 82 should be 83 I think )
    The function is hard coded inside for 40 data rows, and 3 columns of Result data, but you could easily adapt that for different numbers
    Rem 1 gives the entire 2 columns of results , similar to in some of your last Threads. Full data arrays are got here for the ranges, ( in your example 1 - 244 and 1377 – 1620 )

    Rem 2 does some simple maths to get the number of final sections, ( 7 in your example )

    Rem 3 does some not so simple maths to get
    row and column, Top left indices,
    rTL and cTL , of where the output should go. You want
    1,1,1,42,42,42,83 and 1,4,7,1,4,7,1

    Rem 4 Uses Index( arrIn() , {1,2,3,4 } , 0 ) type stuff that you know about for pulling out part of an array to get the data section columns of data

    Rem 5 Pastes out to the worksheet

    Alan



    Typical Output as seen in the next 2 posts,
    Attached Files Attached Files
    Last edited by DocAElstein; 01-01-2019 at 08:13 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    4, 5, 6 and 7 data section output after running Sub SpltTests() from http://www.excelfox.com/forum/showth...0881#post10881
    https://tinyurl.com/yd95w5v2


    _____ Workbook: Sample.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    H
    41
    40
    1416
    80
    1456
    120
    1496
    42
    S1
    S2
    S1
    S2
    S1
    S2
    43
    121
    1497
    161
    1537
    201
    1577
    44
    122
    1498
    162
    1538
    202
    1578
    45
    123
    1499
    163
    1539
    203
    1579
    46
    124
    1500
    164
    1540
    204
    1580
    47
    125
    1501
    165
    1541
    205
    1581
    48
    126
    1502
    166
    1542
    206
    1582
    49
    127
    1503
    167
    1543
    207
    1583
    50
    128
    1504
    168
    1544
    208
    1584
    51
    129
    1505
    169
    1545
    209
    1585
    52
    130
    1506
    170
    1546
    210
    1586
    53
    131
    1507
    171
    1547
    211
    1587
    54
    132
    1508
    172
    1548
    212
    1588
    55
    133
    1509
    173
    1549
    213
    1589
    56
    134
    1510
    174
    1550
    214
    1590
    57
    135
    1511
    175
    1551
    215
    1591
    58
    136
    1512
    176
    1552
    216
    1592
    59
    137
    1513
    177
    1553
    217
    1593
    60
    138
    1514
    178
    1554
    218
    1594
    61
    139
    1515
    179
    1555
    219
    1595
    62
    140
    1516
    180
    1556
    220
    1596
    63
    141
    1517
    181
    1557
    221
    1597
    64
    142
    1518
    182
    1558
    222
    1598
    65
    143
    1519
    183
    1559
    223
    1599
    66
    144
    1520
    184
    1560
    224
    1600
    67
    145
    1521
    185
    1561
    225
    1601
    68
    146
    1522
    186
    1562
    226
    1602
    69
    147
    1523
    187
    1563
    227
    1603
    70
    148
    1524
    188
    1564
    228
    1604
    71
    149
    1525
    189
    1565
    229
    1605
    72
    150
    1526
    190
    1566
    230
    1606
    73
    151
    1527
    191
    1567
    231
    1607
    74
    152
    1528
    192
    1568
    232
    1608
    75
    153
    1529
    193
    1569
    233
    1609
    76
    154
    1530
    194
    1570
    234
    1610
    77
    155
    1531
    195
    1571
    235
    1611
    78
    156
    1532
    196
    1572
    236
    1612
    79
    157
    1533
    197
    1573
    237
    1613
    80
    158
    1534
    198
    1574
    238
    1614
    81
    159
    1535
    199
    1575
    239
    1615
    82
    160
    1536
    200
    1576
    240
    1616
    83
    S1
    S2
    84
    241
    1617
    85
    242
    1618
    86
    243
    1619
    87
    244
    1620
    88
    Worksheet: Result
    Last edited by DocAElstein; 01-01-2019 at 07:54 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. VBA to Reply All To Latest Email Thread
    By pkearney10 in forum Outlook Help
    Replies: 11
    Last Post: 12-22-2020, 11:15 PM
  2. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  3. Replies: 19
    Last Post: 04-20-2019, 02:38 PM
  4. Search List of my codes
    By PcMax in forum Excel Help
    Replies: 6
    Last Post: 08-03-2014, 08:38 AM

Posting Permissions

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