Page 53 of 55 FirstFirst ... 3435152535455 LastLast
Results 521 to 530 of 541

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

  1. #521
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    This is post https://www.excelfox.com/forum/showt...ll=1#post19567
    https://www.excelfox.com/forum/showthread.php/2837-Appendix-Thread-App-Index-Rws()-Clms()-Majic-code-line-Codings-for-other-Threads-Tables-etc-)?p=19567&viewfull=1#post19567
    https://www.excelfox.com/forum/showt...ge53#post19567
    https://www.excelfox.com/forum/showthread.php/2837-Appendix-Thread-App-Index-Rws()-Clms()-Majic-code-line-Codings-for-other-Threads-Tables-etc-)/page53#post19567






    Some further explaining notes for this Thread answer
    https://eileenslounge.com/viewtopic.php?f=27&t=40371
    https://eileenslounge.com/viewtopic....312533#p312533


    Part1
    This is what the first row Header Unique ID looks like
    _____ Workbook: Schedule re-alignment.xls ( Using Excel 2013 32 bit )
    Unique ID 694 697
    Date 01.04.2019 01.04.2019
    Units 33 66
    Worksheet: Part1




    But we want this as the wanted results






    We can get the results in the Excel spreadsheet CSE "Array" Type 2 way sort of way like this



    We want to do that in VBA in the magical code line way of

    arrOut() = Index(arrIn(), Rws(), Clms())

    arrIn() is our 694 697
    Interception and Implicit Intersection theory tells us that using a single 1 will effectively get the same results as the row of 1’s we want, so all we really need to do is get us that Clms() array

    In other words we want to get something like this sort of "vertical" array
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2


    We can do that using the Excel spreadsheet ROW() function to get us a "vertical" array and do a bit of maths on that to get the actual indicia values. There are probably a few ways to do that.
    The following way , in words , is the first way I came up with:
    Using this, ROW(1:26) gets us the array of the correct dimension but it’s a list of sequential numbers, from 1 to 26
    1
    2
    3

    .
    .
    .
    26

    If I subtract 1 from those numbers, Row(1:26)-1 , I start at 0 and end in 25 instead. (I need to do that or else the following maths does not quite get the change over from 1 to 2 row correct, - it is out of step by a row)
    ( This sort of mathematical step works because again of Interception and Implicit Intersection theory – in this case the single 1 will work as if we had 26 1’s in the same "vertical" alignment as what Row(1:26) gives us )
    If I divide the 0 to 25 numbers all by 13, (Row(1:26)-1)/13 , then the first half of the numbers are a number between 0 and 1 and the second half of numbers are a number between 1 and 2
    If I add 1 to all those numbers, ((Row(1:26)-1)/13)+1 , then the first half of the numbers are a number between 1 and 2 and the second half of numbers are a number between 2 and 3.
    If I take the integers of the numbers so far, INT(((Row(1:26)-1)/13)+1) , I end up with what I finally want: I end up with all 1s for the first half, and all 2s for the second half.

    Inside VBA, that would look like this
    Evaluate("INT(((Row(1:26)-1)/13)+1)")
    That should work, and does often, but…
    For Excel from about version 2016 that is OK. Earlier versions sometimes need a little trick to make sure some functions ( the INT in this case ) give us the full array of results rather than the first value. This trick is often a good one
    IF({1}, ______ )

    So finally for good backward Excel version compatibility we would have
    Evaluate("IF({1}, INT(((Row(1:26)-1)/13) )+1)")

    Here is a final macro
    Code:
     Sub makrooPart1()
    Dim Lr As Long, HdCnt As Long
     Let HdCnt = 2
     Let Lr = Cells(Rows.Count, 1).End(xlUp).Row
    Dim NoHds As Long: Let NoHds = (Lr - 1) / HdCnt
    
    ' Clms()
    Dim Clms() As Variant
     Let Clms() = Evaluate("IF({1},INT(((Row(1:26)-1)/13))+1)")
     Let Clms() = Evaluate("IF({1},INT(((Row(1:" & Lr - 1 & ")-1)/" & NoHds & "))+1)")
    
    ' arrOut()=Index(arrIn(),Rws(),Clms())
    Dim arrOut() As Variant
     Let arrOut() = Application.Index(Range("B1:C1"), 1, Clms())
     Let Range("O2:O27") = arrOut()
     Let Range("O2:O27") = Application.Index(Range("B1:C1"), 1, Evaluate("IF({1},INT(((Row(1:26)-1)/13))+1)"))
     Let Range("O2:O27") = Application.Index(Range("B1:C1"), 1, Evaluate("IF({1},INT(((Row(1:" & Lr - 1 & ")-1)/" & NoHds & "))+1)"))
    End Sub
    It should give the results as demoed in Worksheet Part1 in the uploaded file.
    Attached Files Attached Files
    Last edited by DocAElstein; 12-02-2023 at 02:54 PM.

  2. #522
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    This is post https://www.excelfox.com/forum/showt...ll=1#post19568
    https://www.excelfox.com/forum/showthread.php/2837-Appendix-Thread-App-Index-Rws()-Clms()-Majic-code-line-Codings-for-other-Threads-Tables-etc-)?p=19568&viewfull=1#post19568
    https://www.excelfox.com/forum/showt...ge53#post19568
    https://www.excelfox.com/forum/showthread.php/2837-Appendix-Thread-App-Index-Rws()-Clms()-Majic-code-line-Codings-for-other-Threads-Tables-etc-)/page53#post19568






    Some further explaining notes for this Thread answer
    https://eileenslounge.com/viewtopic.php?f=27&t=40371
    https://eileenslounge.com/viewtopic....312533#p312533
    https://eileenslounge.com/viewtopic....312533#p312533



    Part 2
    Re-alignment of data


    This is what we have:




    This is what we want




    We can get the results in the Excel spreadsheet CSE "Array" Type 2 way sort of way like this





    We want to do that in VBA in the magical code line way of

    arrOut() = Index(arrIn(), Rws(), Clms())

    arrIn() is our Range B2:C27


    Column Indicia array, Clms()
    We note first that we have two identical columns. This helps simplify things, as Interception and Implicit Intersection theory tells us that using a single column in such ways will give us the same results as if we used two identical columns. So we only need to get a single "vertical" column of indicia like this
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2

    We did this in Part 1

    Clms() = Evaluate("IF({1},INT((ROW(1:26)-1)/13)+1)")


    Rws()
    We need to get this 2 column x 26 row type array of the form
    1 2
    3 4
    5 6
    7 8
    9 10
    11 12
    13 14
    15 16
    17 18
    19 20
    21 22
    23 24
    25 26
    1 2
    3 4
    5 6
    7 8
    9 10
    11 12
    13 14
    15 16
    17 18
    19 20
    21 22
    23 24
    25 26

    (Note that we have a repeating pattern there**)
    A common way I do this is some combination of:
    _ the Excel Spreadsheet ROW() and COLUMN() functions, since they can return arrays
    and
    _ some mathematical manipulation to get the correct indicia values
    You can mess about a lot and come up with a few different ways. This is the first I came up with:
    This , (Row(1:26)-1) , gives me
    0
    1
    2
    .
    .
    .
    25

    (The -1 is initially a bit of a guess on my behalf, based on my experience that a typical problem in these sort of things when we are wanting to do some sort of repeating pattern**, is that most usually without it, the repeating is slightly off by a single row, ( or column ), and this adjustment brings things back into wack as we want them. So it is a bit of an intuitive guess that this is a good start point).
    Now, if I multiply those numbers so far 2, and then add that to the column numbers, given in a horizontal form, like
    1 2
    , then I get this sort of thing
    0*2+1=1 0*2+2=2
    1*2+1=3 1*2+2=4
    5 6
    7 8

    etc.
    .
    .
    49 50
    51 52

    In Excel spreadsheet syntax we can do that with
    (Row(1:26)-1)*2

    So we almost have what we want. The problem is that instead of the repeating pattern we just have kept going up in numbers
    We need to take off some multiple of 26. For the first half of the numbers that multiple is actually zero, and then for the second half it is 1. We almost have the indicia array we want for the multiplier from the work we did with Clms(). That work got us this
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2

    Subtracting 1 from all those gives us
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1

    So we take our result for Clms() and subtract 1 from it,
    (IF({1},INT((ROW(1:26)-1)/13)+1))-1
    The last 2 things to do is to
    multiply that last result by 26, ((IF({1},INT((ROW(1:26)-1)/13)+1))-1)*26
    ,then having done that
    , that result is subtracted from the numbers that went up to 52

    Finally then, we have something like this
    (((Row(1:26)-1)*2)+COLUMN(A:B))-((IF({1},INT((ROW(1:26)-1)/13)+1))-1)*26

    In VBA we will have
    Evaluate("(((Row(1:26)-1)*2)+COLUMN(A:B))-((IF({1},INT((ROW(1:26)-1)/13)+1))-1)*26")



    This makroo demos the results in worksheet Part2 in the attached file, Schedule re-alignment Demo makroos.xls

    Code:
     Sub makrooPart2()  '  https://eileenslounge.com/viewtopic.php?f=27&t=40371
    ' Clms()
    Dim Clms() As Variant
     Let Clms() = Evaluate("IF({1},INT((ROW(1:26)-1)/13)+1)")
     
    ' Rws()
    Dim Rws() As Variant
     Let Rws() = Evaluate("(((Row(1:26)-1)*2)+COLUMN(A:B))-((IF({1},INT((ROW(1:26)-1)/13)+1))-1)*26")
    
    Dim arrOut() As Variant
     Let arrOut() = Application.Index(Range("B2:C27"), Rws(), Clms())
     Let Range("S2:T27") = arrOut()
     Let Range("S2:T27") = Application.Index(Range("B2:C27"), Evaluate("(((Row(1:26)-1)*2)+COLUMN(A:B))-((IF({1},INT((ROW(1:26)-1)/13)+1))-1)*26"), Evaluate("IF({1},INT((ROW(1:26)-1)/13)+1)"))
    
    End Sub
    Attached Files Attached Files
    Last edited by DocAElstein; 12-02-2023 at 03:00 AM.

  3. #523
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some extra notes for this Thread:
    http://www.eileenslounge.com/viewtopic.php?f=30&t=38460

    Hans Solution http://www.eileenslounge.com/viewtop...297266#p297266
    This is a nice solution which I totally misread, or rather in my ignorance, I did not understand.

    The main point I missed is…
    The solution assumes that the final solution actually has a 26 element 1 dimensional array, and the weight numbers in that array are sorted in alphabetical order, so that the first element represents the weight for “A” and the last Element represents the weight for “Z”, etc.
    ( So the array Letters() is redundant, and only the Weights() array is needed )
    Hans has kindly set me straight and explained where I was going wrong. The final working version of his solution is
    Code:
    Sub Testit()
     MsgBox prompt:=Weight("ZAC")
    End Sub
    ' https://eileenslounge.com/viewtopic.php?f=30&t=38460&sid=4295ec4560088f42492ca29590271a87
    Public Function Weight(S As String) As Long ' http://www.eileenslounge.com/viewtopic.php?p=297266#p297266
    Dim Weights() As Variant  ' Letters() As Variant,
    Dim i As Long
    '    Letters = Array("A", "B", "C", ..., "Z")
    '    Weights = Array(1, 5, 3, ..., 2)
     '                     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
     Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2) ' Watch : - : Weights() :  : Variant/Variant(0 to 25) : Module1.Weight
        For i = 1 To Len(S)
         Let Weight = Weight + Weights(Asc(Mid(S, i, 1)) - 65)
        Next i
    End Function
    How is that working:
    We are looping through each character, then doing something clever to get the running total. The clever bit is getting the array element
    To demonstrate that working consider a couple of examples for the case of a word having an A and a Z in it
    A has the Ascii Code number of 65. So we end up referring to Weights(65-65) = Weights(0) , which is the first element typically in a 1 dimensional array that starts at indicia 0
    Z has the Ascii Code number of 90. So we end up referring to Weights(90-65) = Weights(25) , which is the last element in a 1 dimensional array of 26 elements that starts at indicia 0



    In order for the function to get correct results in the case of lower case letters, then one way to do it, ( assuming you have the correct Weights() array you want for lower case letters), you would need to change the 65 to 97
    Code:
    Sub Testit()
    Debug.Print Tab(4); "ASCII"; Tab(12); "Weight"
    Debug.Print Tab(4); "Code"
     Call Weight("ZAC")
    Debug.Print
     Call WeightLowerCase("zac")
    End Sub
    ' https://eileenslounge.com/viewtopic.php?f=30&t=38460&sid=4295ec4560088f42492ca29590271a87
    Public Function Weight(S As String) As Long ' http://www.eileenslounge.com/viewtopic.php?p=297266#p297266
    Dim Weights() As Variant  ' Letters() As Variant,
    Dim i As Long
     '                     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
     Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2) ' Watch : - : Weights() :  : Variant/Variant(0 to 25) : Module1.Weight
        For i = 1 To Len(S)
         Let Weight = Weight + Weights(Asc(Mid(S, i, 1)) - 65)
         Debug.Print Mid(S, i, 1); Tab(4); Asc(Mid(S, i, 1)); Tab(8); Asc(Mid(S, i, 1)) - 65; Tab(12); Weights(Asc(Mid(S, i, 1)) - 65)
        Next i
    End Function
    Public Function WeightLowerCase(S As String) As Long ' http://www.eileenslounge.com/viewtopic.php?p=297266#p297266
    Dim Weights() As Variant  ' Letters() As Variant,
    Dim i As Long
     '                     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
     Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2) '
        For i = 1 To Len(S)
         Let WeightLowerCase = WeightLowerCase + Weights(Asc(Mid(S, i, 1)) - 97)
         Debug.Print Mid(S, i, 1) & vbTab & Asc(Mid(S, i, 1)) & vbTab & Asc(Mid(S, i, 1)) - 97 & vbTab & Weights(Asc(Mid(S, i, 1)) - 97)
        Next i
    End Function
    

    Here is the Debug.Print output from the last demo coding
    Code:
       ASCII   Weight
       Code
    Z   90  25  2 
    A   65  0   1 
    C   67  2   3 
    
    z   122 25  2
    a   97  0   1
    c   99  2   3

  4. #524
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Here is an alternative single liner ( almost ## ) type solution to the last post. It was much simpler than I expected, and ends up much shorter than these solutions of mine usually do. (## There was a small snag, not solved yet, which means I have to do it in 2 code lines for now. I may take a look at that later here: https://excelfox.com/forum/showthrea...ll=1#post16655 )

    Solution explanation.
    Part 1. Background

    This is all to do with
    _ “my”** ____arrOut()=Index(ArrIn(), Rws(), Clms()) ______ type solutions, ( https://www.excelforum.com/excel-new...ml#post4571172 )
    and also
    _ using the Match in a similar way – ( some time ago I obsessed with trying out Application.Match where the first argument is an array, in a similar way to those of those array arguments Rws() and Clms() in Index. I got so obsessed I littered a sub forum with over long posts until they deleted them all and limited the post size to stop me doing it again. With hindsight, not a bad thing to do, as I could not see the wood for the trees back then. I can now, and its not at all difficult to understand, so I really don’t need all that crap anymore. Let me call that for now “my” **
    ________arrOut() = Match(arrArg1(), arrIn() , 0 )
    ___ type solution.
    ( ** I use the word “my” lightly. – I learnt all this stuff from looking at stuff from Rick Rothstein and snb. ( I am not sure if they “invented it” , or got it from other peoples stuff. if I added anything “new” , it might be some of my detailed explanations, which whilst I don’t know if they are correct, they seem to be a valid theory as they go a long way to explain the results ) )


    Here is a quick demo of how
    _ my ____arrOut()=Match(arrArg1(), arrIn() , 0 )
    ____ works
    Ordinarily, or most usually the first argument is just one thing that you are looking for. As far as I know all documentation tells you that the way Match in Excel works is, ( simplified ) :
    _... you look in the second argument array of things for the thing in the first argument, and , assuming you find it, return the position along where it is, pseudo like
    _____ Match( b , { a, b, c } , 0 ) = 2
    In the practice we sometimes, ( not always ) , find that things in Excel will work with array arguments and return a corresponding array of outputs. So taking that last example, pseudo like
    _____ Match( {b, a} , { a, b, c } , 0 ) = {2, 1}

    So that is a bit of theory out of the way. ( I have done a fuller explanation in a few places of how the Application.Index with Look Up Rows and Columns Arguments as VBA Arrays works in a few places
    https://excelfox.com/forum/showthrea...ll=1#post16455
    https://www.excelforum.com/excel-new...ml#post4571172
    )




    Part 2. Here is my solution examples
    Refering to the first long macro below:

    Rem1 is just making some stuff I need for the demo. I use the string example of “ZAC” as per the original OP example http://www.eileenslounge.com/viewtopic.php?f=30&t=38460 . For reasons given in the next bit, I make an array of the 26 Ascii Code numbers for the capital alphabet characters, A, B. C ….Z , Asskeys() = { 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81 ,82,83,84,85,86,87,88,89,90 }
    My array of the weights values, Weights(), for the characters will be the same size as Asskeys() and will have the corresponding weight value for each of the 26 characters in the same order.
    Once again it will be clear why later. For now, the point is to have arrays of the same size with related things in the same order
    Code:
     ' '   Ascii Code       65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90
    ' '                     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
    ' Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2)  
    Rem 2
    I found a way on the internet to turn my string example into an array of single characters, which is what I will be feeding into my Match as first argument. ( Unfortunately it does not return in each element the character, but rather its Ascii Code. But for my purposes that’s just as good.

    Rem 3 Match
    This is the Match bit, and it tells me the position along where I find the three Ascii Code numbers of “ZAC” in the Ascii Code array, Asskeys()
    We get from match here, a 3 element array, MtchRes(), of the position along, of the characters in “ZAC” in the array Asskeys(). We have organised that the array of weights is organised in the same order, so this will also be the position along of the corresponding weight number in the array of weights, Weights().
    In the example we should have then an array like {26, 1, 3} _ ( if you have followed the logic so far, you can see this is like a pseudo Alphabet position of the characters, Z , A , and C __ (But don’t get confused with Ascii codes, which is pseudo like the official position of characters, and defined by some world standard, that Excel knows about. As example, capital A is listed as Ascii code 65, lowercase a is listed as 97 )

    Rem 4 Index
    The 3 element array of the position along, of the characters in “ZAC” in the array Asskeys(), is effectively the Clms() array we need for a __arrOut()=Index(ArrIn(), Rws(), Clms())__type solution, where the look up array, arrIn() , will be the weights array, Weights()
    The returned array from Index , arrOut(), will be an array, of 3 numbers, which are the weight numbers for the example string “ZAC”.

    Rem 5
    Finally we simply sum the elements of the found weight values, as per the original OP request.
    Code:
    Sub AssKeys()
    Rem 1 Make the arrays and other hard coded things for the demo
    Dim AssKeys(1 To 26) As Long
    Dim Eye As Long
        For Eye = 65 To 90 Step 1
         Let AssKeys(Eye - 64) = Eye
        Next Eye
    ' OR
    '  Dim AssKeys() As Variant: Let AssKey() = Array(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90)
    Dim Weights() As Variant:
     '   Ascii Code       65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90
     '                     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
     Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2)
    Dim ZAC As String
     Let ZAC = "ZAC" ' This is a demo example text string
    Rem 2 String to array
    Dim arrZAC() As Byte: Let arrZAC() = StrConv(ZAC, vbFromUnicode) ' https://stackoverflow.com/questions/13195583/split-string-into-array-of-characters
    Rem 3 Match
    Dim MtchRes() As Variant
     Let MtchRes() = Application.Match(arrZAC(), AssKeys(), 0)
    Rem 4 Index
    Dim arrOut() As Variant
     Let arrOut() = Application.Index(Weights(), 1, MtchRes())
    Rem 5
    Dim Some As Long: Let Some = Application.Sum(arrOut())
    End Sub
    Here the shortening possibilities

    Code:
    Sub BeautifulAsskeys()
    Rem 1 Make the arrays and other hard coded things for the demo
    'Dim Asskeys(1 To 26) As Long
    'Dim Eye As Long
    '    For Eye = 65 To 90 Step 1
    '     Let Asskeys(Eye - 64) = Eye
    '    Next Eye
    ' OR
    '  Dim AssKeys() As Variant: Let AssKey() = Array(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90)
    'Dim Weights() As Variant:
    ' '   Ascii Code       65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90
    ' '                     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
    ' Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2)
    'Dim ZAC As String
    ' Let ZAC = "ZAC" ' This is a demo example text string
    Rem 2 String to array
    Dim arrZAC() As Byte: Let arrZAC() = StrConv("ZAC", vbFromUnicode) ' https://stackoverflow.com/questions/13195583/split-string-into-array-of-characters
    Rem 3 Match
    'Dim MtchRes() As Variant
    ' Let MtchRes() = Application.Match(arrZAC(), Asskeys(), 0)
    ' Let MtchRes() = Application.Match(StrConv(ZAC, vbFromUnicode), Asskeys(), 0)' this does not work
    Rem 4 Index
    'Dim arrOut() As Variant
    ' Let arrOut() = Application.Index(Weights(), 1, MtchRes())
    Rem 5
    Dim Some As Long: Let Some = Application.Sum(Application.Index(Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2), 1, Application.Match(arrZAC(), Array(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90), 0)))
    End Sub
    '
    Sub AsKeys()                                                       '  http://www.eileenslounge.com/viewtopic.php?p=297288#p297288
    Dim arrZAC() As Byte: Let arrZAC() = StrConv("ZAC", vbFromUnicode) ' https://stackoverflow.com/questions/13195583/split-string-into-array-of-characters
    Dim Some As Long: Let Some = Application.Sum(Application.Index(Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2), 1, Application.Match(arrZAC(), Array(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90), 0)))
    End Sub
    







    ** I use the word “my” lightly. – I learnt all this stuff from looking at stuff from Rick Rothstein and snb. ( I am not sure if they “invented it” , or got it from other peoples stuff. if I added anything “new” , it might be some of my detailed explanations, which whilst I don’t know if they are correct, they seem to be a valid theory as they go a long way to explain the results

  5. #525
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Spare post for sharing some documents
    Ersatzpost für die gemeinsame Nutzung einiger Dokumente


    Attachment 3932


    Attachment 3933


    Attachment 3934








    AlanSdattHof15Aug2022.docx
    https://app.box.com/s/xxntrig04ppe7hdd68se882rm3fv2ysw https://bit.ly/3QXSEv0

    AlanSdattHof15Aug2022.doc
    https://app.box.com/s/pt4v46nl28qya2bfycgq2rdfz3a35fq8 https://bit.ly/3STVvqm





    This post links
    AlanSdattHof15Aug2022.docx
    AlanSdattHof15Aug2022.doc
    https://excelfox.com/forum/showthrea...ll=1#post16655
    https://excelfox.com/forum/showthrea...ge55#post16655
    https://excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=16655&viewfull=1#post16655
    https://excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)/page55#post16655
    https://bit.ly/3AEPlmM https://bit.ly/3wmjQvh
    Attached Images Attached Images
    Attached Files Attached Files
    Seasonal greetings :-)

  6. #526
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    In support of this main forum post
    https://excelfox.com/forum/showthrea...-Excel-Formula

    Assuming this is data and wanted results from column D

    _____ Workbook: DogsNutsFormulas.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Code Values Code Value1 Value2 Value3 Value4
    2
    1001
    2101
    1001
    2101
    5205
    2605
    9285
    3
    1001
    5205
    2604
    4256
    7458
    3555
    4
    1001
    2605
    5
    1001
    9285
    6
    2604
    4256
    7
    2604
    7458
    8
    2604
    3555
    9
    Worksheet: SimpleUniqueVLookUp



    Enter this In D2 via CSE, then drag it down:
    =IFERROR(INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$8),0)),"")
    Row\Col
    D
    2
    =IFERROR(INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$8),0)),"")
    3
    =IFERROR(INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D2,$A$2:$A$8),0)),"")


    Alternative formula for earlier versions of Excel:
    =IF(ISERROR(INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$8),0))),"",INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$8),0)))
    Row\Col
    D
    2
    =IF(ISERROR(INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$8),0))),"",INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$8),0)))
    3
    =IF(ISERROR(INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D2,$A$2:$A$8),0))),"",INDEX($A$2:$A$8,MATCH(0,COUNTIF($D$1:D2,$A$2:$A$8),0)))



    Hi Amelynn
    Quote Originally Posted by Amelynn View Post
    …..
    • If after TextBox(n) it is necessary to put the .text or .value
    • If not putting anything is wrong (although it works)
    • What is the difference between the three things……
    I can’t answer most of your question here, unfortunately, because
    _ I have no experience with Textboxes
    _ I am not too familiar with the .Text property.

    I can only tell you the small part that I know about: - what I know about is
    Range__
    Range__.Value
    Range__.Value2


    Range__ object
    Range__ is an object with an extremely large number of properties, methods and various things.
    Range__ is all to do with how Excel organises and uses cells. Understanding the Range__ object is probably one of the most important things to know about in Excel and VBA, especially if you are interested in spreadsheet things.
    But many times, we are only interested in the value that is in a cell. Because most people are often only interested in the value in a cell, Microsoft have made .Value the default of what you get if you just use Range__. So most of the time if you choose to write just Range__ , then in fact , Excel will not see that, instead it will see and use Range__.Value
    It is just personal choice if you choose to use Range__.Value or Range__. Usually there are no problems if you just use Range__ , but I have seen occasions when this caused problems as there may be occasions when Excel tries to refer to the Range__ object instead of the value.
    So personally I prefer to always include the .Value if I am interested in a value. I will only leave out the .Value if I am doing something that wants me to reference the Range__ object. Just personal choice.

    So, in your example, when you used Worksheets("Sheet1").Range("B10") , Excel did not see and use that.
    Instead, Excel saw and used this: Worksheets("Sheet1").Range("B10").Value


    Quote Originally Posted by Amelynn View Post
    ....After the range, should I put .text, .value or just nothing? ...
    So in your examples you could probably just use nothing , but I personally would recommend that you include .Value ( or .Value2 )
    But that is just my personally recommendation

    .Value or .Value2
    .Value is almost the simplest cell value. But not quite. If you are interested in dates or currency, then .Value will show you the date or currency in a date or currency format.
    .Value2 is the most simplest cell value as Excel has it held before any formatting is done.

    Personally I will use .Value2 most of the time, because it may work a little faster or may be less likely to problems caused by awkward cell formatting issues. I think theoretically it is also a bit more efficient to use .Value2

    So….
    Quote Originally Posted by Amelynn View Post
    .....If not putting anything is wrong (although it works).....
    It is not wrong to put nothing. But it is bad practice, as it may cause problems in other situations in Excel VBA
    (More than half of people put nothing, and they will often get a problem later that they don’t understand )



    Quote Originally Posted by Amelynn View Post
    ....Should I necessarily declare that, for example, "Niebla" is a variable of type Str?
    The way that you are using "Niebla" in VBA coding is perfectly alright, because: Most of the time in VBA coding, if VBA sees something enclosed in quotes, _ "__" _ , like
    "xyz"
    , then VBA will take the value of _ xyz _ to be a string.
    Even if , in your coding, you did this
    "3"
    , the VBA would not take the FONT=Courier New]"3"[/FONT] as a number. It would see it as a string, just as it would see this as a string
    "I have 3 Apples"


    Note that VBA is very user friendly with numbers and strings. For example if you pass it a string like "3" in a function wanting a number, the VBA will not error, but instead it will take a number 3 instead.

    In many other computer languages you must be much more careful in defining precisely variable types.




    That is as close as I can come to answering your question.
    But I do know about Range__ , Range__.Value , Range__.Value2 quite well.
    So I am happy to give you any further clarity on those things. Those things are all to do with range referencing in Excel and VBA, which is a very important thing to know about.


    Alan







    Ref
    https://fastexcel.wordpress.com/2011...w-to-avoid-it/
    Seasonal greetings :-)

  7. #527
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some notes in support of this forum main post
    https://excelfox.com/forum/showthrea...ll=1#post16712


    An erroring formula: https://i.postimg.cc/nzbWtGTQ/An-erroring-formula.jpg


    Highlight a section, such as the Match section https://i.postimg.cc/5NxZ0pJB/Highlight-match.jpg


    Hit key F9 https://i.postimg.cc/7P1FwdFP/Hit-ke...esult-is-5.jpg


    This reveals that we have 5 , or in total , 5 + 1 = 6


    So in the VLookUp we are looking at column 6 in the range given by bk
    The names manager tells us which range we want:
    Second formula section is the range bk https://i.postimg.cc/JhBFg23L/range-bk.jpg




    Similarly we can investigate the first section in the erroring formula
    Highlight first formula section https://i.postimg.cc/902syY7j/Highli...la-section.jpg

    Hit key F9 https://i.postimg.cc/wvLStG3V/Hiut-F...st-section.jpg

    This reveals that the Look up value, the value that you are looking for is "DMG1"


    Further investigations by trial and error , reveals that some character combinations in cell A2 cause the error. But I do not know why yet ?

    Examples:
    Not work:
    https://i.postimg.cc/YqbTmg2J/d-not-work.jpg
    https://i.postimg.cc/d0zbVYQ3/d-MG1-not-work.jpg

    Works

    https://i.postimg.cc/3xq6tTv1/MG1-works.jpg

    In fact, it seems that some character combinations are not allowed as the Look Up value generally , for example try another cell, and I can find a character combination that does not work
    https://i.postimg.cc/SK204shH/Not-wo...ters-in-A6.jpg


    I am puzzled.

    In fact if you look in detail at the results you are getting when it does appear to work, then they are not alwaysthe correct values.
    https://postimg.cc/kBnt3Zzg


    Very strange. I am even more puzzled
    ?????






    Update Answer from Sandy https://excelfox.com/forum/showthrea...ll=1#post16717
    Quote Originally Posted by sandy666 View Post
    with formula =VLOOKUP(F$26,bk,MATCH($B$24,bkt,1)+1,0) value $1.55 is returned and so on
    ..just forgot comma on the end or define last argument 0, VLOOKUP(F$26,bk,MATCH($B$24,bkt,1)+1,) so he need to learn how to use VLOOKUP function
    VLOOKUP require all arguments, even if last argument is omitted there should be defined place for it after last comma

    https://i.postimg.cc/15VpN7Hj/ThatsIt.jpg
    ( I thought I had checked that, but missed something somewhere, I don’t know why I missed that, maybe I think also I need to learn how to use VLoopUp properly! )


    Seasonal greetings :-)

  8. #528
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Test

    I see what you are saying its like “the 14th thing along” , like in if it was in a 1 dimensional or 1 “row” array,
    This sort of thing
    _number along{1 _ , 2 , 3 , 4 , 5 , 6 , 7 , 8 _ , 9 _ , 10_, 11_, 12_,13 , 14 __ , 15 , _16}
    ____INDEX({"Part",13,25,37,48,73,101,145,201,289,600,750,1009, "DMG1",4.1,2.85},1,14) = "DMG1"
    Or similarly
    __number along_____{1 _ , 2 , 3 , 4 , 5 , 6 , 7 , 8 _ , 9 _ , 10_, 11_, 12_,13 , 14 __ , 15 , _16}
    __=MATCH("DMG1",{"Part",13,25,37,48,73,101,145,201,289,600,750,1009, "DMG1",4.1,2.85},0) = 14
    (Note I must change the row separating ; before the to a column separating , **

    I also get indexes mixed up and also I mix up item numbers and indexes. Sometimes they are the same, sometimes they have a similar meaning



    ( ** just passing interest, if in a range we talk about the “number along” on any range, then we are talking about the range item number, and this “number along” goes like all columns in a row, then next row and so on.
    So example in both these ranges, the range item number is 14
    Row\Col A B C D E F G H I J K L M N
    1 Part 13 25 37 48 73 101 145 201 289 600 750 1009 DMG1

    Range("A1:N1").Item(14) = "DMG1"



    Row\Col A B C D E F G H I J K L M
    1 Part 13 25 37 48 73 101 145 201 289 600 750 1009
    2 DMG1 $ 4.10 $ 2.85 $ 2.85 $ 1.90 $ 1.55 $ 1.35 $ 1.25 $ 0.95 $ 0.85 $ 0.75 $ 0.75 $ 0.65

    Range("A1:M2").Item(14) = "DMG1"



    Row\Col O P Q R S T U V W
    4 Part 13 25 37 48 73 101 145 201
    5 289 600 750 1009 DMG1 $ 4.10 $ 2.85 $ 2.85 $ 1.90

    Range("O4:W5").Item(14) = "DMG1"

    Here is a very interesting article by a very clever person on all that https://excelfox.com/forum/showthrea...column-looping
    )
    Seasonal greetings :-)

  9. #529
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10

    in VBA if the given string is found then delete everything between two newlines where the string appears.

    In support of this forum thread
    https://excelfox.com/forum/showthrea...ll=1#post16718

    In worksheet String to search is the following:

    _____ Workbook: VBA delete everything between two newlines where the string appears.xlsx ( Using Excel 2007 32 bit )
    Row\Col A
    1
    2 paragraph/line
    3
    4 searched string
    5 #VBA
    Worksheet: String to search

    Here is the given input examples ( The OP gave 4 cells , but for demo here I will put them all in the same code box and separate the 4 examples with a line. Black is the before/input , and Blue the after/ wanted output
    Code:
     in VBA if the given string is found then delete everything between two newlines where the string appears.
    "Looking for help in VBA"
    
    if the given string is found in any paragraph/line excel cell then delete everything between two newlines where the string appears. in VBA if the given string is found then delete everything between two newlines where the string appears.
    "Looking for help in VBA"searched*string
    
    if the given string is found in any excel cell then delete everything between two newlines where the string appears.
     in VBA if the given string is found then delete everything between two newlines where the string appears.
    "Looking for help in VBA"
    
    
    
    
    if the given string is found in any excel cell then delete everything between two newlines where the string appears.
    
    
    
    
    in VBA if the given string is found then delete everything between two newlines where the string appears. "Looking for help in #VBA" if the given string is found in any excel cell then delete paragraph/line everything between two newlines where the string appears. in VBA if the given string is found then delete paragraph/line everything between two newlines where the string appears. "Looking for help in VBA" if the given string is found in any excel cell then delete everything between two newlines where the string appears. searched*string in VBA if the given string is found then delete everything between two newlines where the string appears. "Looking for help in VBA" if the given string is found in any excel cell then delete everything between two newlines where the string appears.
    in VBA if the given string is found then delete everything between two newlines where the string appears. "Looking for help in VBA" if the given string is found in any paragraph/line excel cell then delete everything between two newlines where the string appears. in VBA if the given string is found then delete everything between two newlines where the string appears. "Looking for help in VBA"searched*string if the given string is found in any excel cell then delete everything between two newlines where the string appears. in VBA if the given string is found then delete everything between two newlines where the string appears. "Looking for help in VBA" if the given string is found in any excel cell then delete everything between two newlines where the string appears.
    in VBA if the given string is found then delete everything between two newlines where the string appears. "Looking for help in #VBA" if the given string is found in any excel cell then delete paragraph/line everything between two newlines where the string appears. in VBA if the given string is found then delete paragraph/line everything between two newlines where the string appears. "Looking for help in VBA" if the given string is found in any excel cell then delete everything between two newlines where the string appears. searched*string in VBA if the given string is found then delete everything between two newlines where the string appears. "Looking for help in VBA" if the given string is found in any excel cell then delete everything between two newlines where the string appears.
    OK so it looks quite clear what is needed. The OPs explanation does confirm to this, …. if the given string is found in any excel cell then delete everything between two newlines where the string appears.
    … How can I delete sentences with a specific keyword in excel cells in all sheets?
    …..but without the example it was much more difficult to understand and may have been interpreted to mean something else..




    Putting the explanation of what is wanted a bit clearer,
    There is text in some cells. The text is split into paragraphs or lines, that is to say we see multi-line text, something like
    Code:
    How are you?
    
    Well I am OK Bro today
    Enjoying a wank just now.
    What we want to do is: Modify the text in cells in this way: If certain words are found in a paragraph or line, then all the text in that line needs to be deleted. Lets say in that example, Bro was one of the words to search for. In that case, the text should be modified so as to look like this
    Code:
    How are you?
    
    
    Enjoying a wank just now.
    We remove all the text, Well I am OK Bro today, but it looks like the lines stay there.


    We are manipulating text and some form of line separation is involved, so its usually a good idea to look carefully at the actual characters: Almost immediately I think of Splitting and Joining text where the thing to split by or use to join together will be a text line separator, which can vary. Hence important to take a look, so I will, here, later
    https://excelfox.com/forum/showthrea...ll=1#post16727
    Seasonal greetings :-)

  10. #530
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    In support of this main Forum Thread
    https://excelfox.com/forum/showthrea...earched-string

    Input
    Code:
    					
    "#VBA: keep only one searched string searched string searched string searched string.
    #VBA: keep only searched string one searched string.
    The list of search stings searchedCSV string searched string is given in sheet 2.
    In sheet1, with #VBA check if a given string is CSV searched string found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with CSV searched string multiple column data in multiple rows as well as in a CSV or text file."				
    				
    "searched string searched string #VBA: keep only one searched string.
    #VBA: keep only one searched string.
    searched string searched string searched stringThe list of search stings is given in sheet 2.
    In sheet1, with #VBA check if a given string is found more than once #VBA #VBA #VBA #VBA #VBA #VBA #VBA #VBA #VBA #VBA #VBA #VBA in a paragraph/line. If found more than once then keep only one. #VBA #VBA #VBA #VBA 
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."				
    				
    "#VBA: keep only one searched string.
    #VBA: keep only one searched string.
    The list of search stings is given in sheet 2.
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file. #VBA: keep only one searched string.
    #VBA: keep only one searched string. searched string searched string searched string searched string
    The list of search stings is given in sheet 2. searched string searched string searched string searched string
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."				
    				
    				
    				
    				
    	"#VBA: #VBA  keep only one searched string.
    #VBA: #VBA #VBAkeep only one searched string.
                  searched string searched string  searched string  searched string  searched string
    In sheet1, with #VBA check if a given string is found more than #VBA once in a paragraph/line. If found more than #VBA once then keep only one.
    
    #VBA: keep only one searched string.
    The list of search stings is given in sheet 2.
    In sheet1, with #VBA check if a given string is found more than #VBA once in a paragraph/line. If found more than #VBA once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."			
    				
    				
    				"#VBA: keep only one searched string.
    
    
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file. #VBA: keep only one searched string.
    
    
    In sheet1, with #VBA check if a  paragraph/line given string is found more than once in a paragraph/line paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."
    Output
    Code:
    				
    "#VBA: keep only one searched string .
    #VBA: keep only searched string one .
    The list of search stings searchedCSV string searched string is given in sheet 2.
    In sheet1, with #VBA check if a given string is CSV searched string found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with CSV searched string multiple column data in multiple rows as well as in a CSV or text file."				
    				
    "searched string  #VBA: keep only one searched string.
    #VBA: keep only one searched string.
    searched string searched stringThe list of search stings is given in sheet 2.
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one. 
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."				
    				
    "#VBA: keep only one searched string.
    #VBA: keep only one searched string.
    The list of search stings is given in sheet 2.
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file. #VBA: keep only one searched string.
    #VBA: keep only one searched string.  
    The list of search stings is given in sheet 2. searched string
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."				
    				
    				
    				
    				
    	"#VBA:   keep only one searched string.
    #VBA: keep only one searched string.
                  searched string
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    
    #VBA: keep only one searched string.
    The list of search stings is given in sheet 2.
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."			
    				
    				
    				"#VBA: keep only one searched string.
    
    
    In sheet1, with #VBA check if a given string is found more than once in a paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file. #VBA: keep only one searched string.
    
    
    In sheet1, with #VBA check if a  paragraph/line given string is found more than once in a paragraph/line paragraph/line. If found more than once then keep only one.
    I want to do this both in an excel sheet with multiple column data in multiple rows as well as in a CSV or text file."
    Seasonal greetings :-)

Similar Threads

  1. Replies: 185
    Last Post: 05-22-2024, 10:02 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
  •