Consulting

Results 1 to 5 of 5

Thread: Array Relative Erase Variables but Next

  1. #1
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location

    Array Relative Erase Variables but Next

    Array Relative Erase Variables but Next

    Hi Parters,

    I have 2columns A:B and in ColumnB i have the values to compare in loop.

    i have a array in loop that filter values of ColumnB and return relative array.

    but in next loop gives error.

    error with preserve old of looping or error with retur blank results.

    i think i need erase old value and continues Looping ForNext value.

    Please, i need values of array relative to next loop.

    if i make For 4 to 4 or For 5 to 5 runs ok.
    if i make For 4 to 5 - First Loop (4) ok, but next loop (5) not.
    ''======================================
    example PseudoCode:

    For 4 to 5
    If c.Value = ValorLvalue Then StudentMarks(n) = c.Row
    next

    1oLoop
    StudentMarks(1) ''=row
    StudentMarks(2) ''=row

    2oLoop
    StudentMarks(1) ''=row
    StudentMarks(2) ''=row
    ''======================================

    Sample workbook file atacched
    array-relative-Xman1.zip

    Thank you very much!

          
       Dim ValorLvalue As Long
        For ValorLvalue = 4 To 5
        
        Dim Rng As Range, c As Range
        Dim StudentMarks()
        Dim n As Long
        
         ReDim StudentMarks(1 To ColunaY.Count)  ''XMAN2000 MUDAR DEPOIS PARA COLUNAY.COUNT
          
    For Each c In ColunaY
    If c.Value = ValorLvalue Then
                n = n + 1
                StudentMarks(n) = c.Row
    End If
    Next c
    ''========================================================
            Dim FirstCelYiABSOLUTA As Range
            Dim SecondCelYiABSOLUTA As Range
    
    
            Set FirstCelYiABSOLUTA = WayPts.Cells(ColunaY.Row, "B")
            Set SecondCelYiABSOLUTA = WayPts.Cells(ColunaY.Row + 1, "B")
                    
            Dim FirstCelXiABSOLUTA As Range
            Dim SecondCelXiABSOLUTA As Range
    
    
            Set FirstCelXiABSOLUTA = WayPts.Cells(ColunaX.Row, "A")
            Set SecondCelXiABSOLUTA = WayPts.Cells(ColunaX.Row + 1, "A")
    ''========================================================
    
    
       MsgBox "ValorLvalue " & ValorLvalue
       MsgBox "FirstCelYiABSOLUTA " & FirstCelYiABSOLUTA
       MsgBox "SecondCelYiABSOLUTA " & SecondCelYiABSOLUTA
     
       MsgBox "StudentMarks1 " & StudentMarks(1)  ''PROBLEM I NEED VALUE OF VALORLVALUE(5)
       MsgBox "StudentMarks2 " & StudentMarks(2) ''PROBLEM I NEED VALUE OF VALORLVALUE(5)
        
        Erase StudentMarks
    Next ValorLvalue
    
    
    End Sub
    edit: i put an "Erase StudentMarks" above "Next" in final of code but not working!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For some reason Dim n as Long within the loop is not resetting n to 0. Try forcing it
       Dim n As Long
        n = 0
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location
    Quote Originally Posted by mdmackillop View Post
    For some reason Dim n as Long within the loop is not resetting n to 0. Try forcing it
       Dim n As Long
        n = 0
    Yes, mdmackillop, works fine, you save my weenkend!
    great weekend for you.

    i put :

     n = 0
      Next ValorLvalue
    If other user have other observation to explain about this problem, please tell me.

  4. #4
    I don't know what you goal is, but I think you'd better reduce your code to:

    Sub M_snb()
       For j = 4 To [max(backup!B1:B6000)]
          [backup!D1] = j
          MsgBox j & vbTab & ["from "&match(backup!D1,backup!B1:B6000,0)] & ["  to "&max((backup!B1:B6000=backup!D1)*row(backup!B1:B6000))]
       Next
    End Sub

  5. #5
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location
    Quote Originally Posted by snb View Post
    I don't know what you goal is, but I think you'd better reduce your code to:

    Sub M_snb()
       For j = 4 To [max(backup!B1:B6000)]
          [backup!D1] = j
          MsgBox j & vbTab & ["from "&match(backup!D1,backup!B1:B6000,0)] & ["  to "&max((backup!B1:B6000=backup!D1)*row(backup!B1:B6000))]
       Next
    End Sub
    Hi,Snb,
    you are a master of arrays, i know!

    my goal is use this array to return in more simple and eficient way a filtered aray with reuse of the array, not many arrays like Myarray(1) x times, but only 1one Myarray(1) to all results of ech looping.

    think, how i am know the number of array(x) of each new looping (4 to 125) (5 to 125) (6 to125) etc.
    very mutch loopings, very mutch arrays results.

    but i am poor in vba, your code is hard to me now.
    but i will study your code to try simplify it more.

    thanks

    great array here
    https://usefulgyaan.wordpress.com/20...ter-in-arrays/

Posting Permissions

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