Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: IF({1},___) Index returning array

  1. #11
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    OK, here's another thread that confirms my claim. Phew!

    VBA Trick of the Week :: Avoid Loop for Range Calculations – Evaluate | Useful Gyaan

    Specifically, read the below excerpt


    Suppose we’ve some text values in range A1:A10 and we want to extract and keep only the first three letters of the values in all cells of this range. We could try to do so using the below code:
    Code:
        Set rngData = ThisWorkbook.Worksheets("Sheet1").Range("A1:B10")
        rngData = Evaluate("Left(" & rngData.Address & ",3)")
    BUT, you’ll find it does not work. It will fill the whole range with first 3 letters of cell A1. The reason is that if the Excel function used in Evaluate does not accept an array, the Evaluate function will not return an array. So in order to make this function return an array we need to modify the code slightly like this:

    Code:
        Set rngData = ThisWorkbook.Worksheets("Sheet1").Range("A1:A10")
        rngData = Evaluate("if(Row(1:10),left(" & rngData.Address & ",3))")
    In this case, ROW(1:10) returns an array of numbers from 1 to 10. Any numeric value other than 0 returned from a logical function is considered as TRUE, So there are 10 vertical TRUE values. For each TRUE, it will return the corresponding cell’s value from A1:A10.
    And the reason why it was working in the previous examples was probably because we weren't using any other function within the EVALUATE function. Hopefully, this makes more sense.
    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

  2. #12
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    By the way, you can reference this thread to the OP at the other forum, as long as you feel it is relevant, and is not intended to manipulate traffic. Hope that's as straight as it gets.
    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

  3. #13
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Wow, great, Thanks for all that info. - I'll work me way throught it now (or maybe tomorrow night in my daily "VBA Hour" - It is nearly bed-time now here in Bavaria)

    Thanks again
    Alan

    .P.s....
    By the way, you can reference this thread to the OP at the other forum, as long as you feel it is relevant, and is not intended to manipulate traffic. Hope that's as straight as it gets.
    ...OK....(should be OK - Rick referrences this Forum in all his replies!)

  4. #14
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Wow, great, Thanks for all that info. - I'll work me way throught it now (or maybe tomorrow night in my daily "VBA Hour" - It is nearly bed-time now here in Bavaria)

    Thanks again
    Alan

    .P.s....
    By the way, you can reference this thread to the OP at the other forum, as long as you feel it is relevant, and is not intended to manipulate traffic. Hope that's as straight as it gets.
    ...OK....(should be OK - Rick referrences this Forum in all his replies!)

  5. #15
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10

    IF({1},___) Index returning array

    On sobering up, this last solution from Mr xladept, looks like a nice solution to look at to get a bit of knowledge about what this “AutoFilter” is about.
    So for the benefit of any novices catching this Thread , here is my “take” on what the “AutoFilter” is about, and in particular what we can learn from the last routines..

    I haven’t used stuff like “AutoFilter” much myself: It seems to be one of those things that profis, use, but which can be a bit daunting to the novice VBA user..

    Here is the last routine in a slightly SAlanitised form.
    Code:
    Sub NormanXLFoxAfterASecondThink_2() ' xladept  http://www.excelfox.com/forum/showthread.php/2293-Move-values-in-rows-at-the-end-of-the-preceding-row?p=10878#post10878
    Rem 0
    Dim wa As Worksheet, wb As Worksheet: Set wb = Sheets("Before"): Set wa = Sheets("AfterASecondThink")
     wb.Activate ' We are working on wb, which means the the  Range   stuff beow should probably better be  wb.Range   ,   as it they arent, then it might be best to activate that worksheet because usually an unqualifed  Range  call will go to the active worksheet
    Rem 1 "The Filter thing" Part 1
            wb.UsedRange.AutoFilter Field:=1, Criteria1:="=2018*"
    Rem 2 Loop all rows, "Hidden" and "Visible"
    Dim r As Long
        For r = 2 To Range("A" & Rows.Count).End(xlUp).Row + 1 ' For this code we must +1 to be sure to catch any last rouge number, beacus looking at this point, VBA will go back up to the last now "visible" row. This is just how VBA is wired to work. VBA uses and sees both "visible" and "invisible" rows, but  .End(xlUp)   is the VBA equivalent to keys  Ctrl+Up  which takes us to the last  "visible"  cell in a row
            If Rows(r).RowHeight = 0 And Rows(r - 1).RowHeight <> 0 And IsNumeric(Left(Range("A" & r), 1)) Then
             Range("A" & r - 1) = Range("A" & r - 1) & "," & Range("A" & r)
            Else
            End If
        Next r
    Rem 3 "The Filter thing" Part 2
     wb.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Destination:=wa.Cells(1, 1)
     wb.UsedRange.AutoFilter
    Rem 4
     wa.Activate
     wa.Columns("A:A").AutoFit
    End Sub
    Rem 1 is the main part of the code concerned with “AutoFilter”. ( Typically a code line such as this would form about half of the important code lines related to a use of “AutoFilter” )
    The main “AutoFilter” bit in this code line is
    ______.AutoFilter Field:=1, Criteria:="=2018*"
    ( There are more optional arguments available, but I don’t understand them all yet ( https://docs.microsoft.com/en-us/off...nge.autofilter ) )
    This “AutoFilter” thing is a Method of a Range. In this example it is applied to UsedRange. UsedRange is a bit of a dodgy thing to use, as it often does not give you what you expect. In this example we will get the range A1 : A40 if we are .
    Field:=__ is column of the range that we are interests in. In our case we only have 1, but if we had a couple of columns then we could use 1 or 2 etc. This determines where VBA is going to look for the criteria you give it in the next argument.
    Criteria:=__ is what is looked for. This argument will take “wild cards” , which in this example means basically that VBA will look in the first column of our range for a text which starts with "=2018". The * is taken as meaning anything.

    Take look at the code….
    ( Hit Alt+F11 from the spreadsheet and look for it in a code module,
    or
    _1 Hit Alt+F8 to get the routine dialogue window )
    _2 Select the routine
    _3 Select to edit or work on the code
    Alt8 SelectRoutine EditCode .JPG : https://imgur.com/aRHLZbC
    )

    Click anywhere in the routine.
    Run it in F8 debug mode and stop close after wb.UsedRange.AutoFilter Field:=1, Criteria:="=2018*" ,
    or
    Click in the margin close after wb.UsedRange.AutoFilter Field:=1, Criteria:="=2018*" to put a stop in , and run using the play button
    Stop Play.JPG : https://imgur.com/9M9uQlU

    So you want to get at the point where the routine is paused something like this
    Paused.JPG : https://imgur.com/alAqyS4

    At this part of the routine progression, if you look at the main data sheet, you will now see that it has changed from the original , ( Worksheets: BEFORE http://www.excelfox.com/forum/showth...-row#post10870 ) , and now looks lIke
    _____ Workbook: Data Sample.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    1
    Configurable Alerts blabla:
    11
    2018, 1, 90515, 10024515, G9, SBlabla (HQ), CHE, BLABLA, blabla, 10012098, 12003.5
    12
    2018, 1, 90629, 10022334, P3, BLABLA blabla (blablabla), CHE, BLABLA,blabla, 10033609, 13941.72
    13
    2018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah,
    15
    2018, 1, 90765, 10012123, P4, Ch of Blabla(Blabla of Blabla), CHE, BLA-BLA,Bla Blabla,
    17
    2018, 1, 90712, 10022908, P4, Snr BLA Off (Strat BLa, BLA), CHE, BLABLA,Bla BLabla, 10023234,
    19
    2018, 1, 90919, 10020984, P2, Ass BLA Balbla, CHE, BLA,Blabla, 10033098, 10486.33
    20
    2018, 1, 95706, 10023098, NB, Assc BLA Blabal (LatBLAa), BLA, BLABLABLA,Blabla, 10034318,
    29
    2018, 1, 95716, 10018763, NA, Asst BLA Off (Blabla & Multi-BLa), BLA, BLA,Bla, 10097776, 8607.96
    30
    2018, 1, 99716, 10026132, G5, Snr BLA Asst (Bla Blabla), BLA, BLABLA,bla BLa, 18767043, 5477.44
    31
    2018, 1, 99716, 10016545, G6, Blabla Blabla (BLA), BLA, BLABLABLA,Blabla, 1097029,
    41
    Worksheet: BEFORE
    That screen shot and the next code sections illustrate a lot of what / how the “AutoFilter” is.
    When talking in Excel jargon about a spreadsheet looking like that last screenshot we might often say that we have the lines 11, 12, 13 , 15, 17, 19, 20 , 29, 30 , 31 as “visible” in the range A1:A40.
    Or we might say the Range A1:A40 has “visible cells” of cells A11, A12, A13 , A15, A17, A19, A20 , A29, A30 , A31. Or we might say something similar, but the word “visible” will likely be used somehow.

    Rem 2 This section gives a nice insight as to how the “AutoFilter” works.
    ( The Looping of this section is not so typically seen in coding using “AutoFilter” ).
    Because of the particular requirement of this Thread, we need to check if we had any “rouge numbers”, which seem to have slipped off the line they were likely intended to be on and appear in the next line.
    So the question is, having used the “AutoFilter” effectively to do the main filtering out of the lines we did not want, how do we now check the lines above our “visible” lines. … Well, the fact that the row height is checked and the complete routine seems to do what we want, illustrates to us that what “AutoFilter” appears to do: It appears to reduce the height of the rows which we do not want to 0 height. As far as we Humans perceive this, we regard such lines as “invisible”. To VBA they are not invisible. To VBA they are lines similar to any others. One of the VBA range properties of what we regard as “invisible” is a row height of 0. In other words our “invisible” row is a “row of zero height” to VBA.
    We might say that the routine has at this point “filtered out” lines other than those with the text bit of “2018,” at the start. VBA has actually reduced the row height to 0 of all but the cells with “2018,” at the start.
    The section of coding here in Rem 2 is similar to the looping in my original code in post #7, except that we no longer need to check for the bit of “2018,”. We simply look at lines of zero height in the now filtered range which also have a row above which has not been “filtered out” . In other words those two criteria are satisfied by
    ____If Rows(r).RowHeight = 0 And Rows(r - 1).RowHeight <> 0
    With that condition met, then the “rogue numbers” are tacked on in a similar way as in my routine.
    Here we have
    Range("A" & r - 1).Value = Range("A" & r - 1).Value & Range("A" & r).Value
    Because this routine differs in general from mine, in that it works directly with the spreadsheet, this step is somewhat more obvious than in my routine. ( My routine uses what is called a VBA arrays type coding, which puts all data in an internal array, manipulates that to produce a final output array which is then pasted into the worksheet in one go. Using “AutoFilter” ) is strictly called the using “Range AutoFilter Method” , and as such comes under the general heading of Worksheet functions which are mostly applied to worksheets. My code does more traditional elementary coding and mathematics internally to achieve similar final results )

    Rem 3
    The lines here would be typical of the second part the coding in a simple usage of “AutoFilter
    Usually we would like to have what is to us “visible” after the filtering, to be in some “normal” form.
    Doing a simple .Copy of the range of what we “see” will probably give us copied in the clipboard some form of a total range of discontinuous cells, in our case something like A1,A11:A13,A15,A17,A19:A20,A29:A31. VBA tends in such a case of all the cells being “in line” to actual Hold that as if it was single 11 row range. So copying and pasting will likely get us near what we finally want.
    There tends in the practice to be odd things that might catch you out doing that simple copy and paste. One thing to note is that the “AutoFilter” often catches the first row whether it meats the criteria or not. ( This is generally regarded as an option to keep the header row in any filtering work, which is often practically useful ). Sometimes adding a bit in a code line to be sure of copying just our “visible” rows is often a good idea. Taking these things into account, and knowing what you are doing, ( which I don’t too well here ) , will mean that rather than a simple line like
    wb.UsedRange.Copy Destination:=wa.Cells(1, 1)
    Instead something like this would be used to be sure to get what you want
    wb.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Destination:=wa.Cells(1, 1)
    The .Offset(1, 0) is perhaps easy to understand as this will mean that we will not get the header row copied.
    The .SpecialCells(xlCellTypeVisible) in one function is easy to Understand: it will limit us to not going too far down the worksheet with our copying. Copying to our last row would probably often do the same, but there are likely subtle reasons only to gained by experience to make the use of .SpecialCells(xlCellTypeVisible).
    The things talked about, in particular in this Rem 3 code section, are the subtleties that can trip up the inexperienced. That is why “AutoFilter” way tends to be the way a profi might do it. So it is probably better left to them to do it. I tend to avoid it for fear of getting it wrong.
    ( Mr xladept of course, is, in reality, not quite what you might call a “Junior” thing, so he likely by now should know what he is doing …. :-) )

  6. #16
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10

    IF({1},___) Index returning array

    On sobering up, this last solution from Mr xladept, looks like a nice solution to look at to get a bit of knowledge about what this “AutoFilter” is about.
    So for the benefit of any novices catching this Thread , here is my “take” on what the “AutoFilter” is about, and in particular what we can learn from the last routines..

    I haven’t used stuff like “AutoFilter” much myself: It seems to be one of those things that profis, use, but which can be a bit daunting to the novice VBA user..

    Here is the last routine in a slightly SAlanitised form.
    Code:
    Sub NormanXLFoxAfterASecondThink_2() ' xladept  http://www.excelfox.com/forum/showthread.php/2293-Move-values-in-rows-at-the-end-of-the-preceding-row?p=10878#post10878
    Rem 0
    Dim wa As Worksheet, wb As Worksheet: Set wb = Sheets("Before"): Set wa = Sheets("AfterASecondThink")
     wb.Activate ' We are working on wb, which means the the  Range   stuff beow should probably better be  wb.Range   ,   as it they arent, then it might be best to activate that worksheet because usually an unqualifed  Range  call will go to the active worksheet
    Rem 1 "The Filter thing" Part 1
            wb.UsedRange.AutoFilter Field:=1, Criteria1:="=2018*"
    Rem 2 Loop all rows, "Hidden" and "Visible"
    Dim r As Long
        For r = 2 To Range("A" & Rows.Count).End(xlUp).Row + 1 ' For this code we must +1 to be sure to catch any last rouge number, beacus looking at this point, VBA will go back up to the last now "visible" row. This is just how VBA is wired to work. VBA uses and sees both "visible" and "invisible" rows, but  .End(xlUp)   is the VBA equivalent to keys  Ctrl+Up  which takes us to the last  "visible"  cell in a row
            If Rows(r).RowHeight = 0 And Rows(r - 1).RowHeight <> 0 And IsNumeric(Left(Range("A" & r), 1)) Then
             Range("A" & r - 1) = Range("A" & r - 1) & "," & Range("A" & r)
            Else
            End If
        Next r
    Rem 3 "The Filter thing" Part 2
     wb.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Destination:=wa.Cells(1, 1)
     wb.UsedRange.AutoFilter
    Rem 4
     wa.Activate
     wa.Columns("A:A").AutoFit
    End Sub
    Rem 1 is the main part of the code concerned with “AutoFilter”. ( Typically a code line such as this would form about half of the important code lines related to a use of “AutoFilter” )
    The main “AutoFilter” bit in this code line is
    ______.AutoFilter Field:=1, Criteria:="=2018*"
    ( There are more optional arguments available, but I don’t understand them all yet ( https://docs.microsoft.com/en-us/off...nge.autofilter ) )
    This “AutoFilter” thing is a Method of a Range. In this example it is applied to UsedRange. UsedRange is a bit of a dodgy thing to use, as it often does not give you what you expect. In this example we will get the range A1 : A40 if we are .
    Field:=__ is column of the range that we are interests in. In our case we only have 1, but if we had a couple of columns then we could use 1 or 2 etc. This determines where VBA is going to look for the criteria you give it in the next argument.
    Criteria:=__ is what is looked for. This argument will take “wild cards” , which in this example means basically that VBA will look in the first column of our range for a text which starts with "=2018". The * is taken as meaning anything.

    Take look at the code….
    ( Hit Alt+F11 from the spreadsheet and look for it in a code module,
    or
    _1 Hit Alt+F8 to get the routine dialogue window )
    _2 Select the routine
    _3 Select to edit or work on the code
    Alt8 SelectRoutine EditCode .JPG : https://imgur.com/aRHLZbC
    )

    Click anywhere in the routine.
    Run it in F8 debug mode and stop close after wb.UsedRange.AutoFilter Field:=1, Criteria:="=2018*" ,
    or
    Click in the margin close after wb.UsedRange.AutoFilter Field:=1, Criteria:="=2018*" to put a stop in , and run using the play button
    Stop Play.JPG : https://imgur.com/9M9uQlU

    So you want to get at the point where the routine is paused something like this
    Paused.JPG : https://imgur.com/alAqyS4

    At this part of the routine progression, if you look at the main data sheet, you will now see that it has changed from the original , ( Worksheets: BEFORE http://www.excelfox.com/forum/showth...-row#post10870 ) , and now looks lIke
    _____ Workbook: Data Sample.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    1
    Configurable Alerts blabla:
    11
    2018, 1, 90515, 10024515, G9, SBlabla (HQ), CHE, BLABLA, blabla, 10012098, 12003.5
    12
    2018, 1, 90629, 10022334, P3, BLABLA blabla (blablabla), CHE, BLABLA,blabla, 10033609, 13941.72
    13
    2018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah,
    15
    2018, 1, 90765, 10012123, P4, Ch of Blabla(Blabla of Blabla), CHE, BLA-BLA,Bla Blabla,
    17
    2018, 1, 90712, 10022908, P4, Snr BLA Off (Strat BLa, BLA), CHE, BLABLA,Bla BLabla, 10023234,
    19
    2018, 1, 90919, 10020984, P2, Ass BLA Balbla, CHE, BLA,Blabla, 10033098, 10486.33
    20
    2018, 1, 95706, 10023098, NB, Assc BLA Blabal (LatBLAa), BLA, BLABLABLA,Blabla, 10034318,
    29
    2018, 1, 95716, 10018763, NA, Asst BLA Off (Blabla & Multi-BLa), BLA, BLA,Bla, 10097776, 8607.96
    30
    2018, 1, 99716, 10026132, G5, Snr BLA Asst (Bla Blabla), BLA, BLABLA,bla BLa, 18767043, 5477.44
    31
    2018, 1, 99716, 10016545, G6, Blabla Blabla (BLA), BLA, BLABLABLA,Blabla, 1097029,
    41
    Worksheet: BEFORE
    That screen shot and the next code sections illustrate a lot of what / how the “AutoFilter” is.
    When talking in Excel jargon about a spreadsheet looking like that last screenshot we might often say that we have the lines 11, 12, 13 , 15, 17, 19, 20 , 29, 30 , 31 as “visible” in the range A1:A40.
    Or we might say the Range A1:A40 has “visible cells” of cells A11, A12, A13 , A15, A17, A19, A20 , A29, A30 , A31. Or we might say something similar, but the word “visible” will likely be used somehow.

    Rem 2 This section gives a nice insight as to how the “AutoFilter” works.
    ( The Looping of this section is not so typically seen in coding using “AutoFilter” ).
    Because of the particular requirement of this Thread, we need to check if we had any “rouge numbers”, which seem to have slipped off the line they were likely intended to be on and appear in the next line.
    So the question is, having used the “AutoFilter” effectively to do the main filtering out of the lines we did not want, how do we now check the lines above our “visible” lines. … Well, the fact that the row height is checked and the complete routine seems to do what we want, illustrates to us that what “AutoFilter” appears to do: It appears to reduce the height of the rows which we do not want to 0 height. As far as we Humans perceive this, we regard such lines as “invisible”. To VBA they are not invisible. To VBA they are lines similar to any others. One of the VBA range properties of what we regard as “invisible” is a row height of 0. In other words our “invisible” row is a “row of zero height” to VBA.
    We might say that the routine has at this point “filtered out” lines other than those with the text bit of “2018,” at the start. VBA has actually reduced the row height to 0 of all but the cells with “2018,” at the start.
    The section of coding here in Rem 2 is similar to the looping in my original code in post #7, except that we no longer need to check for the bit of “2018,”. We simply look at lines of zero height in the now filtered range which also have a row above which has not been “filtered out” . In other words those two criteria are satisfied by
    ____If Rows(r).RowHeight = 0 And Rows(r - 1).RowHeight <> 0
    With that condition met, then the “rogue numbers” are tacked on in a similar way as in my routine.
    Here we have
    Range("A" & r - 1).Value = Range("A" & r - 1).Value & Range("A" & r).Value
    Because this routine differs in general from mine, in that it works directly with the spreadsheet, this step is somewhat more obvious than in my routine. ( My routine uses what is called a VBA arrays type coding, which puts all data in an internal array, manipulates that to produce a final output array which is then pasted into the worksheet in one go. Using “AutoFilter” ) is strictly called the using “Range AutoFilter Method” , and as such comes under the general heading of Worksheet functions which are mostly applied to worksheets. My code does more traditional elementary coding and mathematics internally to achieve similar final results )

    Rem 3
    The lines here would be typical of the second part the coding in a simple usage of “AutoFilter
    Usually we would like to have what is to us “visible” after the filtering, to be in some “normal” form.
    Doing a simple .Copy of the range of what we “see” will probably give us copied in the clipboard some form of a total range of discontinuous cells, in our case something like A1,A11:A13,A15,A17,A19:A20,A29:A31. VBA tends in such a case of all the cells being “in line” to actual Hold that as if it was single 11 row range. So copying and pasting will likely get us near what we finally want.
    There tends in the practice to be odd things that might catch you out doing that simple copy and paste. One thing to note is that the “AutoFilter” often catches the first row whether it meats the criteria or not. ( This is generally regarded as an option to keep the header row in any filtering work, which is often practically useful ). Sometimes adding a bit in a code line to be sure of copying just our “visible” rows is often a good idea. Taking these things into account, and knowing what you are doing, ( which I don’t too well here ) , will mean that rather than a simple line like
    wb.UsedRange.Copy Destination:=wa.Cells(1, 1)
    Instead something like this would be used to be sure to get what you want
    wb.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Destination:=wa.Cells(1, 1)
    The .Offset(1, 0) is perhaps easy to understand as this will mean that we will not get the header row copied.
    The .SpecialCells(xlCellTypeVisible) in one function is easy to Understand: it will limit us to not going too far down the worksheet with our copying. Copying to our last row would probably often do the same, but there are likely subtle reasons only to gained by experience to make the use of .SpecialCells(xlCellTypeVisible).
    The things talked about, in particular in this Rem 3 code section, are the subtleties that can trip up the inexperienced. That is why “AutoFilter” way tends to be the way a profi might do it. So it is probably better left to them to do it. I tend to avoid it for fear of getting it wrong.
    ( Mr xladept of course, is, in reality, not quite what you might call a “Junior” thing, so he likely by now should know what he is doing …. :-) )

  7. #17
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    ABCDE
    1Produnt
    2Name
    3Chocolate-europe aroma4ChocChoc
    4Chocolate-Cookies0ChocChoc
    5Banana-Chocolate-Split10BanaBana
    6Limette-Käsekuchen16LimeLime
    7Erdbeere-Quark8ErdbErdb
    8Erdbeere-Mix0ErdbErdb
    9Jamaica Sun6JamaJama
    10Waldbeeren0WaldWald
    11
    12
    13
    14LOOKUP Table
    15Product Name
    16Haselnuß-Walnuß-aromatisiert
    17Tiramisu2
    18Chocolate-colonial blend
    19Chocolate-europe aroma4
    20Chocolate-Cookies
    21Jamaica Sun6
    22Himbeere-Joghurt
    23Erdbeere-Quark8
    24Erdbeere-Mix
    25Banana-Chocolate-Split10
    26Waldbeeren
    27Kirsche12
    28Kirsche-grüner Apfel

    Sheet1



    Worksheet Formulas
    CellFormula
    B3=VLOOKUP(A3,$A$16:$C$33,3,FALSE)
    B4=VLOOKUP(A4,$A$16:$C$33,3,FALSE)
    B5=VLOOKUP(A5,$A$16:$C$33,3,FALSE)
    B6=VLOOKUP(A6,$A$16:$C$33,3,FALSE)
    B7=VLOOKUP(A7,$A$16:$C$33,3,FALSE)
    B8=VLOOKUP(A8,$A$16:$C$33,3,FALSE)
    B9=VLOOKUP(A9,$A$16:$C$33,3,FALSE)
    B10=VLOOKUP(A10,$A$16:$C$33,3,FALSE)
    D3=LEFT(A3,4)
    D4=LEFT(A4,4)
    D5=LEFT(A5,4)
    D6=LEFT(A6,4)
    D7=LEFT(A7,4)
    D8=LEFT(A8,4)
    D9=LEFT(A9,4)
    D10=LEFT(A10,4)


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

    Error and Error Handling VBA Summary







































    Error Handling Code line _______________________


    Notes


    On Error Resume Next



    Makes code always carry on after error line. Clears the exception – So works time and time again, But retains infomation of last error in Err object



    On Error GoTo Label/Line



    Does not clear the exception. Just goes to the indicated Label or Line Number (Typically at that label or line number would be code lines for an error handling routine ) It is Prevented by default ( due to it not clearing the exception ) from working more than once



    On Error GoTo 0



    Does not clear the exception Disables any enabled error handler This Clears the Err object



    On Error GoTo -1



    Clears the exception (* Deactivates any enabled error handler) Does not disable any enabled error handler This Clears the Err object



    Resume


    Clears the exception (* Deactivates any enabled error handler) Does not disable any enabled error handler. Makes code try again at error line. ( Be careful as can lead to an infinite loop of retrying!!) Does not retain infomation of last error:Clears Err object



    Resume Next



    As Resume , but resumes after line which errored



    Resume Label/Line Number



    As Resume , but resumes at Label/Line number



    * Deactivated means: "The trap is reset: but not currently working - It is "primed" ". It is enabled, but not activated.


    Err : An object 6 Properties containing infomation about last error and 2 Methods, .Raise and .Clear


    Erl : A Function returning line number of last error or 0 if no line number is present at erroring code line.


    vbObjectError : Probably broken or no one remembers what it does - A plie of wank - forget about it!


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

    create invoice with user form

    Error and Error Handling VBA Summary













































    Error Handling Code line ORNeRe_GoRoT_N0Nula_1_____


    Notes



    On Error Resume Next



    Makes code always carry on after error line. Clears the exception – So works time and time again, But retains infomation of last error in Err object



    On Error GoTo Label/Line



    Does not clear the exception. Just goes to the indicated Label or Line Number (Typically at that label or line number would be code lines for an error handling routine ) It is Prevented by default ( due to it not clearing the exception ) from working more than once



    On Error GoTo 0



    Does not clear the exception Disables any enabled error handler This Clears the Err object



    On Error GoTo -1



    Clears the exception (* Deactivates any enabled error handler) Does not disable any enabled error handler This Clears the Err object



    Resume



    Clears the exception (* Deactivates any enabled error handler)    Does not disable any enabled error handler. Makes code try again at error line. ( Be careful as can lead to an infinite loop of retrying!!) Does not retain infomation of last error:Clears Err object



    Resume Next



    As Resume , but resumes after line which errored



    Resume Label/Line Number



    As Resume , but resumes at Label/Line number



    * Deactivated means: "The trap is reset: but not currently working - It is "primed" ". It is enabled, but not activated.


    Err : An object 6 Properties containing infomation about last error and 2 Methods, .Raise and .Clear


    Erl : A Function returning line number of last error or 0 if no line number is present at erroring code line.


    vbObjectError : Probably broken or no one remembers what it does - A plie of wank - forget about it!


Similar Threads

  1. Replies: 3
    Last Post: 03-07-2022, 05:12 AM
  2. Automated Search Results Returning Nothing
    By Bill in forum Excel Help
    Replies: 8
    Last Post: 10-15-2020, 06:31 PM
  3. Sort an array based on another array - VBA
    By Admin in forum Excel Help
    Replies: 6
    Last Post: 10-06-2016, 06:03 AM
  4. VBA Trick of the Week :: Slicing an Array Without Loop - Application.Index
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 06-12-2013, 04:40 PM
  5. MLookup not returning results
    By jomili in forum Excel Help
    Replies: 5
    Last Post: 12-20-2012, 09:16 PM

Posting Permissions

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