Page 39 of 55 FirstFirst ... 29373839404149 ... LastLast
Results 381 to 390 of 541

Thread: Appendix Thread. App Index Rws() Clms() Majic code line Codings for other Threads, Tables etc.)

  1. #381
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    MID( SUBSTITUTE(Text,Delim,REPT(" ",LEN(Text))) , element*LEN(Text)-(LEN(Text)-1) , LEN(Text) )

    Test...

    MID( SUBSTITUTE(Text,Delim,REPT(" ",LEN(Text))) , (element*LEN(Text)) - (LEN(Text)-1) , LEN(Text) )
    MID( SUBSTITUTE(Text,Delim,REPT(" ",LEN(Text))) , (element*LEN(Text)) - ( LEN(Text) ) , LEN(Text) )

    Row\Col
    A
    B
    C
    1
    What is pseudo is in the Cell to the left ( column B )
    2
    Example get the first thing, 1 from the Text string "1,3,5"
    1,3,5
    my original test text
    3
    Length
    5
    the length in characters of my original test text
    4
    ( Rept " " ) x Length 5 spaces like "12345"
    5
    Substitute in the original string ( B2 ) 5 spaces for each comma seperator
    1_____3_____5
    like "1123453123455" is 13 characters
    6
    I apply to B5 the MID function starting at (1x5)-(5-1)=1 and for a length of 5
    1____
    like "11234"
    7
    I apply to B5 the MID function starting at (1x5)-(5)=0 and for a length of 5
    #VALUE!
    Excel doesn't forgive me for trying to start at 0 !!!!
    8
    9
    Example get the second thing, 3 from the Text string "1,3,5"
    1,3,5
    my original test text
    10
    Length
    5
    the length in characters of my original test text
    11
    ( Rept " " ) x Length 5 spaces like "12345"
    12
    Substitute in the original string ( B9 ) 5 spaces for each comma seperator
    1_____3_____5
    like "1123453123455" is 13 characters
    13
    I apply to B12 the MID function starting at (2x5)-(5-1)=6 and for a length of 5
    _3___
    like "13123"
    14
    I apply to B12 the MID function starting at (2x5)-(5)=5 and for a length of 5
    __3__
    like "12312"
    15
    16
    Example get the third thing, 5 from the Text string "1,3,5"
    1,3,5
    my original test text
    17
    Length
    5
    the length in characters of my original test text
    18
    ( Rept " " ) x Length 5 spaces like "12345"
    19
    Substitute in the original string ( B16 ) 5 spaces for each comma seperator
    1_____3_____5
    like "1123453123455" is 13 characters
    20
    I apply to B19 the MID function starting at (3x5)-(5-1)=11 and for a length of 5
    __5
    like "125" Note: I try to do length 5, but Excel forgives me and gives the 3 it has available
    21
    I apply to B19 the MID function starting at (1x5)-(5)=0 and for a length of 5
    ___5
    like "1235" Note: I try to do length 5, but Excel forgives me and gives the 4 it has available

    Row\Col
    B
    1
    2
    1,3,5
    3
    =LEN(B2)
    4
    =REPT(" ",B3)
    5
    =SUBSTITUTE(B2,",",B4)
    6
    =MID(B5,(1*B3)-(B3-1),B3)
    7
    =MID(B5,(1*B3)-(B3),B3)
    8
    9
    1,3,5
    10
    =LEN(B9)
    11
    =REPT(" ",B10)
    12
    =SUBSTITUTE(B9,",",B11)
    13
    =MID(B12,(2*B10)-(B10-1),B10)
    14
    =MID(B12,(2*B10)-(B10),B10)
    15
    16
    1,3,5
    17
    =LEN(B16)
    18
    =REPT(" ",B17)
    19
    =SUBSTITUTE(B16,",",B18)
    20
    =MID(B19,(3*B17)-(B17-1),B17)
    21
    =MID(B19,(3*B17)-(B17),B17)

    Row\Col
    A
    B
    C
    7
    I apply to B5 the MID function starting at (1x5)-(5)=0 and for a length of 5
    #VALUE!
    Excel doesn't forgive me for trying to start at 0 when using MID

  2. #382
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    MID( SUBSTITUTE(Text,Delim,REPT(" ",LEN(Text))) , element*LEN(Text)-(LEN(Text)-1) , LEN(Text) )

    Test...

    MID( SUBSTITUTE(Text,Delim,REPT(" ",LEN(Text))) , (element*LEN(Text)) - (LEN(Text)-1) , LEN(Text) )
    MID( SUBSTITUTE(Text,Delim,REPT(" ",LEN(Text))) , (element*LEN(Text)) - ( LEN(Text) ) , LEN(Text) )

    Row\Col
    A
    B
    C
    1
    What is pseudo is in the Cell to the left ( column B )
    2
    Example get the first thing, 1 from the Text string "1,3,5"
    1,3,5
    my original test text
    3
    Length
    5
    the length in characters of my original test text
    4
    ( Rept " " ) x Length 5 spaces like "12345"
    5
    Substitute in the original string ( B2 ) 5 spaces for each comma seperator
    1_____3_____5
    like "1123453123455" is 13 characters
    6
    I apply to B5 the MID function starting at (1x5)-(5-1)=1 and for a length of 5
    1____
    like "11234"
    7
    I apply to B5 the MID function starting at (1x5)-(5)=0 and for a length of 5
    #VALUE!
    Excel doesn't forgive me for trying to start at 0 !!!!
    8
    9
    Example get the second thing, 3 from the Text string "1,3,5"
    1,3,5
    my original test text
    10
    Length
    5
    the length in characters of my original test text
    11
    ( Rept " " ) x Length 5 spaces like "12345"
    12
    Substitute in the original string ( B9 ) 5 spaces for each comma seperator
    1_____3_____5
    like "1123453123455" is 13 characters
    13
    I apply to B12 the MID function starting at (2x5)-(5-1)=6 and for a length of 5
    _3___
    like "13123"
    14
    I apply to B12 the MID function starting at (2x5)-(5)=5 and for a length of 5
    __3__
    like "12312"
    15
    16
    Example get the third thing, 5 from the Text string "1,3,5"
    1,3,5
    my original test text
    17
    Length
    5
    the length in characters of my original test text
    18
    ( Rept " " ) x Length 5 spaces like "12345"
    19
    Substitute in the original string ( B16 ) 5 spaces for each comma seperator
    1_____3_____5
    like "1123453123455" is 13 characters
    20
    I apply to B19 the MID function starting at (3x5)-(5-1)=11 and for a length of 5
    __5
    like "125" Note: I try to do length 5, but Excel forgives me and gives the 3 it has available
    21
    I apply to B19 the MID function starting at (1x5)-(5)=0 and for a length of 5
    ___5
    like "1235" Note: I try to do length 5, but Excel forgives me and gives the 4 it has available

    Row\Col
    B
    1
    2
    1,3,5
    3
    =LEN(B2)
    4
    =REPT(" ",B3)
    5
    =SUBSTITUTE(B2,",",B4)
    6
    =MID(B5,(1*B3)-(B3-1),B3)
    7
    =MID(B5,(1*B3)-(B3),B3)
    8
    9
    1,3,5
    10
    =LEN(B9)
    11
    =REPT(" ",B10)
    12
    =SUBSTITUTE(B9,",",B11)
    13
    =MID(B12,(2*B10)-(B10-1),B10)
    14
    =MID(B12,(2*B10)-(B10),B10)
    15
    16
    1,3,5
    17
    =LEN(B16)
    18
    =REPT(" ",B17)
    19
    =SUBSTITUTE(B16,",",B18)
    20
    =MID(B19,(3*B17)-(B17-1),B17)
    21
    =MID(B19,(3*B17)-(B17),B17)

    Row\Col
    A
    B
    C
    7
    I apply to B5 the MID function starting at (1x5)-(5)=0 and for a length of 5
    #VALUE!
    Excel doesn't forgive me for trying to start at 0 when using MID

  3. #383
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    post to use later

  4. #384
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    post to use later

  5. #385
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post



    Before Source worksheet


    _____ Workbook: Transfer data_marasAlan_1.xlsm ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH
    1 Number Unique ID Name Title Platform Filter Salary Add1 Add2 Add3 Add4 Add5 Add6 Add7 Add8 Add9 Add10 Add11 Add12 copy1 copy2 copy3 copy4 copy5 copy6 copy7 Total
    4 3 3658 Lalu Lead C Filter2 300 0 6 6 0 6 0 6 0 0 0 0 0 0 0 1 1 2 0 4
    9 2 563 Vidu_xx Manager Java Filter2 400 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 12 0 0 1 21
    10 2 563 Vidu_max Manager Java Filter2 425 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 12 0 0 2 22
    12 2 563 Vidu Manager Java Filter2 400 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 13 0 0 21
    16 2 354 Sai Operator C++ Filter2 150 0 0 0 23 0 0 2 0 0 0 0 0 0 0 24 0 0 0 24
    17 2 333 Fran Operator SQL Filter2 150 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
    18 3 239 Jack_max Lead SQL Filter2 566 0 0 0 0 0 0 0 45 0 0 0 0 4 4 0 8 4 0 20
    19 3 239 Jack Lead SQL Filter2 300 0 0 0 0 0 0 0 46 0 0 0 0 4 4 4 8 4 0 24
    23 4 222 Andy Operator Java Filter2 150 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 14 8 26
    24 1 123 Ram Manager Java Filter2 400 0 0 3 0 0 0 0 0 0 55 0 0 12 0 0 0 0 3 15
    36 1 26 Som Operator C Filter2 150 0 0 2 0 7 0 0 0 0 0 0 333 0 0 4 0 6 0 22 32
    Worksheet: Sheet1

  6. #386
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post



    Before destination worksheet


    _____ Workbook: Workbook2_1.xlsx ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K L M N O P
    1 Unique ID Name Title Platform Salary Sum copy1 copy2 copy3 copy4 copy5 copy6 copy7
    2
    Worksheet: Sheet1


    Destination After

    _____ Workbook: Workbook2_1.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    1
    Unique ID
    Name
    Title
    Platform
    Salary
    Sum
    copy1
    copy2
    copy3
    copy4
    copy5
    copy6
    copy7
    2
    3658 Lalu Lead C
    £300
    24
    1
    1
    2
    3
    563 Vidu_xx Manager Java
    £400
    0
    8
    12
    1
    4
    563 Vidu_max Manager Java
    £425
    0
    8
    12
    2
    5
    563 Vidu Manager Java
    £400
    0
    8
    13
    6
    354 Sai Operator C++
    £150
    25
    24
    7
    333 Fran Operator SQL
    £150
    2
    8
    239 Jack_max Lead SQL
    £566
    45
    4
    4
    8
    4
    9
    239 Jack Lead SQL
    £300
    46
    4
    4
    4
    8
    4
    10
    222 Andy Operator Java
    £150
    0
    4
    14
    8
    11
    123 Ram Manager Java
    £400
    58
    12
    3
    12
    26 Som Operator C
    £150
    342
    4
    6
    22
    Worksheet: Sheet1

  7. #387
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Macro for last two posts

    Code:
    ' https://www.excelforum.com/excel-programming-vba-macros/1338596-transferring-data.html#post5458446
    ' _  First i wanted to filter column G from workbook 1 to "Filter 2" and transfer only filter 2 data to workbook 2.
    ' _  Then transferring like i wanted to transfer column C (source) to column B (destination) , column D to D, Column L to Column G, etc.
    ' _  I wanted to sum from column P to colum AA and transfer those sum to destination at column H
    ' _ Then copy from column AB to AH and paste in I to O in destination
    
    Sub Transfer_maras_1()
    Dim a(), arrOut__(), Cls(), Cls_v() As String, Rws(), asum
        Dim Rng As Range, Rng_v As Range, Rng_vVls() As Variant, cel As Range
        Dim i As Integer, ii As Integer
    Dim Pth As String: Let Pth = ThisWorkbook.Path & Application.PathSeparator '   Const pth = "c:\Users\User\Downloads\"      '<---- use own path
    Const wnm = "Workbook2_1.xlsx"                   'your workbook name
    Rem 1 the main data range from source
        With ThisWorkbook.Sheets("Sheet1")
         Set Rng = Range("a1:aH" & 36 & "")   '  Range("a1:ag" & 36 & "")   '  hard coded for testing         .UsedRange.Rows.Count)
         Let a() = Rng.Value           '    The main source data range
         Let Cls() = Rng.Rows(1).Value '    The header row
         ReDim Rws(1 To UBound(a))     '    The row indicies of the rows we are intersted in from the filtered range ##### this will likely be much too big at this stage but we will correct that later
        End With
    Rem 2 building a single column array for the summed colums
        Set Rng_v = Rng.Columns(2).SpecialCells(xlCellTypeVisible)  '  for  maras  datas this will be 11 data rows and the header 0 12 rows in total
                          'Rng_vVls() = Rng_v.Value2  '  This is for my testing only - this will give me just first area
        If Rng_v.Count > 1 Then
            ReDim asum(1 To Rng_v.Count) '  1 D array to hold sum values - I wanted to sum from column O to column Z and transfer those sum to destination at column I
            For Each cel In Rng_v
                If cel.Row > 1 And cel.Value <> "" Then
                 Let ii = ii + 1
                 Let asum(ii) = Evaluate("sum(o" & cel.Row & ": z" & cel.Row & ")") ' Evaluate Range way to sum a range
                 Let i = i + 1
                 Let Rws(i) = cel.Row
                End If
            Next
            If ii > 0 Then ReDim Preserve asum(1 To ii) ' Our array is one element too big with an empty element, so thhis takes off that extra unwanted element
            If i > 0 Then ReDim Preserve Rws(1 To i)    ' Our array is much too big so this makes it the correct size ####
        Else ' case no data rows, only a header row
        End If
        If Rng_v.Count = 1 Or i = 0 Then
            MsgBox "No rows to transfer."
            Exit Sub
        End If
    Rem 2
        Workbooks.Open Filename:=Pth & wnm
    '2a) Gets the column indicies of the columns wanted from the data worksheet
        With ActiveWorkbook
            With .Sheets("Sheet1")
            Dim vTemp As Variant
             vTemp = Application.Match(.UsedRange.Rows(1), Rng.Rows(1), 0) '  This gives a 1 D array and each element has either the position of the header in the destination workbook, or an error if it did not find it
             '  { 2 ,  error  , 3  , 4 ,  5 ,  11  , error  ,  27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
             ' So the above line tells us where there is an error in a match with the header names
             Let vTemp = Application.IfError(vTemp, "x") ' Instead of the vbError , a text of  "x"  is put into the array
             '  { 2 ,  x   , 3  , 4 ,  5 ,  11  , x  ,  27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
             Let vTemp = Filter(vTemp, "x", False, 0) ' take out the  "x"s
             '  { 2 ,  x   , 3  , 4 ,  5 ,  11  , x  ,  27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
             Let Cls_v() = Filter(Application.IfError(Application.Match(.UsedRange.Rows(1), Rng.Rows(1), 0), "x"), "x", False, 0)
             '  { 2   , 3  , 4 ,  5 ,  11  ,   27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
    '2b)    Typical arrOut()=AppIndex(arrIn(), Rws(), Clms())
             Let arrOut__() = Application.Index(a(), Application.Transpose(Rws()), Cls_v())  '   Typical arrOut()=AppIndex(arrIn(), Rws(), Clms())
    '2c)    arrOut__() is not quite the final array we want. Its condensed missing out a couple of empty columns, so in code section '2b) we pick out the sections we want and put them in the appropriate place.
                With .Range("B2")   '    UsedRange.Offset(1)
                    '.ClearContents
                    .Resize(UBound(Rws()), 1) = Application.Index(arrOut__(), Evaluate("row(1:" & UBound(Rws()) & ")"), 1) ' column B in output
                    .Offset(, 2).Cells(1).Resize(UBound(Rws()), 4).Value = Application.Index(arrOut__(), (Evaluate("row(1:" & UBound(Rws()) & ")")), Application.Transpose(Evaluate("row(2:" & UBound(arrOut__(), 2) & ")")))  ' column D to G
                    .Offset(, 7).Cells(1).Resize(UBound(Rws()), UBound(arrOut__(), 2) - 5).Value = Application.Index(arrOut__(), Evaluate("row(1:" & UBound(Rws()) & ")"), Application.Transpose(Evaluate("row(6:" & UBound(arrOut__(), 2) & ")"))) ' column  I to O
                    .Offset(, 6).Cells(1).Resize(UBound(Rws())) = Application.Transpose(asum) ' sums column H
                End With
            End With
            '.Save
        End With
    '    Set Rng = Nothing
    '    Set Rng_v = Nothing
    End Sub
    





    _._______________________________

    Here is a before and after…
    https://excelfox.com/forum/showthrea...ll=1#post15278
    https://excelfox.com/forum/showthrea...ll=1#post15279

    Macro
    https://excelfox.com/forum/showthrea...ll=1#post15277

    Files
    Transfer data_marasAlan_1.xlsm : https://app.box.com/s/p8kf5vo8jesql3n47sd1bzgm57qdpwdv
    Workbook2_1.xlsx : https://app.box.com/s/3d9gmeb2nlyr4gg9q802kk5mjgze8cl5

  8. #388
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post


    Source Workbook

    _____ Workbook: Transfer data_marasAlan_2.xlsm ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH AI
    1 Number Unique ID Name Title Platform Filter Salary Add1 Add2 Add3 Add4 Add5 Add6 Add7 Add8 Add9 Add10 Add11 Add12 copy1 copy2 copy3 copy4 copy5 copy6 copy7
    2 1 123 Ram Manager Java Filter2 £400 3 55 12 3 222
    9 1 26 Som Operator C Filter2 £150 1,013
    10 2 354 Sai Operator C++ Filter2 £150 23 2 24 1,126
    17 2 563 Vidu Manager Java Filter2 £400 8 12 147
    18 3 239 Jack Lead SQL Filter2 £300 45 4 4 8 4 149
    19 4 222 Andy Operator Java Filter2 £150 4 14 8 151
    24 2 333 Fran Operator SQL Filter2 £150 1 1 161
    25 3 3658 Lalu Lead C Filter2 £300 6 6 6 6 1 1 2 163
    30
    31
    Worksheet: Sheet1

  9. #389
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post




    Designation workbook before

    _____ Workbook: Workbook2_2.xlsx ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K L M N O P Q
    1 Unique ID Gap Name Title Platform Salary Gap Total copy1 copy2 copy3 copy4 copy5 copy6 copy7
    2
    Worksheet: sheet1

    Destination workbook after running macro Sub Transfer_marasAlan_2()

    _____ Workbook: Workbook2_2.xlsx ( Using Excel 2007 32 bit )
    Row\Col B C D E F G H I J K L M N O P
    1 Unique ID Gap Name Title Platform Salary Gap Total copy1 copy2 copy3 copy4 copy5 copy6 copy7
    2 123 Ram Manager Java £400 58 12 3 222
    3 26 Som Operator C £150 0 1,013
    4 354 Sai Operator C++ £150 25 24 1,126
    5 563 Vidu Manager Java £400 0 8 12 147
    6 239 Jack Lead SQL £300 45 4 4 8 4 149
    7 222 Andy Operator Java £150 0 4 14 8 151
    8 333 Fran Operator SQL £150 2 161
    9 3658 Lalu Lead C £300 24 1 1 2 163
    10
    Worksheet: sheet1

  10. #390
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    macro for last two posts

    Code:
    Option Explicit
    Sub Transfer_marasAlan_2() '
    Dim a(), Cls(), Cls_v() As String, Rws(), aSum(), arrOut__()
    Dim Rng As Range, Rng_v As Range, Cel As Range, WbDest As Workbook
    Dim i As Integer, ii As Integer
    Dim Pth As String
     Let Pth = ThisWorkbook.Path & Application.PathSeparator '  Const Pth = "C:\Users\L026936\Desktop\Excel\"      '<---- use own path
    Const wnm = "Workbook2_2.xlsx"              'your workbook name
        '     Application.ScreenUpdating = False
    Rem 1 the main data range from source
        With ThisWorkbook.Sheets("Sheet1")
         Set Rng = .Range("a1:ag" & 25 & "")    '  Hardcoded for demonstration purposes       .UsedRange.Rows.Count)
         Let a() = Rng.Value                    '  main complete data range
         Let Cls() = Rng.Rows(1).Value          '  header row array
         ReDim Rws(1 To UBound(a))              '  This will be much too big initially - its the full all row size, but we will only want a reduced filtered number of rows - later #### this will be corrected
        End With
        Set Rng_v = Rng.Columns(2).SpecialCells(xlCellTypeVisible) ' this gets just the range we see, so will be likely a range of lots of areas
        If Rng_v.Count > 1 Then
    Rem 2 building a single column array for the summed colums
     ReDim aSum(1 To Rng_v.Count)                ' this is "one row too big" **
            For Each Cel In Rng_v
                If Cel.Row > 1 And Cel.Value <> "" Then
                 Let i = i + 1
                 Let aSum(i) = Evaluate("sum('[Transfer data_marasAlan_2.xlsm]Sheet1'!o" & Cel.Row & ": '[Transfer data_marasAlan_2.xlsm]Sheet1'!z" & Cel.Row & ")")
                 Let Rws(i) = Cel.Row
                End If
            Next
            If i > 0 Then
            ReDim Preserve aSum(1 To i)         ' **  this sets the correct size
            ReDim Preserve Rws(1 To i)          ' #### this sets just enought row size for our final output array
             Let aSum() = Application.Transpose(aSum())  ' we need a "virtical" "column" array
             Let Rws() = Application.Transpose(Rws())    ' we need a virtical array in the second argumant of the  Typical arrOut()=AppIndex(arrIn(), Rws(), Clms())   code line
            End If
        Else ' case only header range visible
        End If
        If Rng_v.Count = 1 Or i = 0 Then
            MsgBox "No rows to transfer."
            Exit Sub
        End If
        On Error Resume Next    '     https://eileenslounge.com/viewtopic.php?f=30&t=35861&start=20
         Set WbDest = Workbooks(wnm) ' will error if workbook is not yet open
            If Err.Number > 0 Then Workbooks.Open Filename:=Pth & wnm ' we test to see if we have an error and if we do themn we kknow to open the workbook
        On Error GoTo 0
         Set WbDest = ActiveWorkbook
    '2a) Gets the column indicies of the columns wanted from the data worksheet
        With WbDest '  ActiveWorkbook
            With .Sheets("Sheet1")
            Dim vTemp As Variant ' just for demo purposes
             Let vTemp = Application.Match(.UsedRange.Rows(1), Rng.Rows(1), 0) '  This gives a 1 D array and each element has either the position of the header in the destination workbook, or an error if it did not find it
             '  { 2 ,  error  , 3  , 4 ,  5 ,  11  , error  ,  error ,  27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
             ' So the above line tells us where there is an error in a match with the header names
             Let vTemp = Application.IfError(vTemp, "x") ' Instead of the vbError , a text of  "x"  is put into the array
             '  { 2 ,  x   , 3  , 4 ,  5 ,  11  , x , x,   ,  27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
             Let vTemp = Filter(vTemp, "x", False, 0) ' take out the  "x"s
             '  { 2    , 3  , 4 ,  5 ,  11   ,  27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
             Let Cls_v() = Filter(Application.IfError(Application.Match(.UsedRange.Rows(1), Rng.Rows(1), 0), "x"), "x", False, 0)
             '  { 2   , 3  , 4 ,  5 ,  11  ,   27 ,  28 ,  29  , 30 ,  31 ,  32 ,  33  }
    '2b) Typical arrOut()=AppIndex(arrIn(), Rws(), Clms())
             Let arrOut__() = Application.Index(a(), Rws(), Cls_v())
     '2c)    arrOut__() is not quite the final array we want. Its condensed missing out a couple of empty columns, so in code section '2c) we pick out the sections we want and put them in the appropriate place. In addition we paste in the sum columns that we got in section Rem 2
                With Range("B2")  '    .UsedRange.Offset(1)
                 .Resize(UBound(Rws), 1) = arrOut__()  '  arrOut__() is 8 columns, but this linw will just put the first column in
                 Let Rws() = Evaluate("row(1:" & UBound(arrOut__()) & ")")  '  for convenience again we are using the variable  Rws()   for sequential rows for  our arrOut__()  as we want all rows in the order that they are there
                .Offset(, 2).Cells(1).Resize(UBound(arrOut__()), 4).Value = Application.Index(arrOut__(), Rws(), Array(2, 3, 4, 5))  '  columns D to G
                .Offset(, 8).Cells(1).Resize(UBound(Rws()), UBound(arrOut__(), 2) - 5).Value = Application.Index(arrOut__(), Rws(), Array(6, 7, 8, 9, 10, 11, 12))  '  columns J to P
                .Offset(, 7).Cells(1).Resize(UBound(Rws())) = aSum()  ' put the totals column in I
                End With
            End With
    '        .Save
        End With
    '    Set Rng = Nothing
    '    Set Rng_v = Nothing
    End Sub
    
    



    _._______________________________

    Here is a before and after…
    https://excelfox.com/forum/showthrea...ll=1#post15276
    https://excelfox.com/forum/showthrea...ll=1#post15273


    Macro
    https://excelfox.com/forum/showthrea...ll=1#post15272

    Files
    Transfer data_marasAlan_2.xlsm : https://app.box.com/s/749a78z2ku4m1s1tg3fvgs1z1ud4s325
    Workbook2_2.xlsx : https://app.box.com/s/13yh30a77spsluauck3nif309pic8fuz

Similar Threads

  1. Replies: 189
    Last Post: 02-06-2025, 02:53 PM
  2. Replies: 3
    Last Post: 03-07-2022, 05:12 AM
  3. HTML (Again!) arrOut()=Index(arrIn(),Rws(),Clms()
    By DocAElstein in forum Test Area
    Replies: 1
    Last Post: 08-23-2014, 02:27 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
  •