PDA

View Full Version : [SOLVED:] Array Relative Erase Variables but Next



xman2000
04-22-2017, 11:52 AM
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
18998

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!

mdmackillop
04-22-2017, 02:06 PM
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

xman2000
04-22-2017, 02:50 PM
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 (http://www.vbaexpress.com/forum/member.php?87-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.

snb
04-23-2017, 03:29 AM
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

xman2000
04-23-2017, 02:27 PM
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/2013/05/28/filter-in-arrays/