ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Array Question (https://www.excelbanter.com/excel-programming/305424-array-question.html)

hotherps[_88_]

Array Question
 
When this code runs it starts to assign values in the array if th
conditions are true, but if the statements avaluate to false it move
to the next number in the array. Basically it is jumbling up m
results.

Is there a way to tell the array to evaluate each number across th
enitre named range before moving on to the next number? Thanks


For Each cell In range("G11:I125")
c = Array(5,4,3,2,1)
For i = 0 To 5
J = 356
K = 305
If Cells(J, c(i)).Value - 1 = Cells(K, c(i)) And cell.Value "" An
Cells(cell.Row, c(i) + 97) = "x" Then _
cell.Value = Cells(9, c(i) + 97)
Next i
Nex

--
Message posted from http://www.ExcelForum.com


Norman Jones

Array Question
 
Hi Hotherps,

If I understand you correctly, you need to invert the loops:

c = Array(5, 4, 3, 2, 1)

J = 356
K = 305

For i = 0 To 5
For Each cell In Range("G11:I125")
If Cells(J, c(i)).Value - 1 = Cells(K, c(i)) _
And cell.Value "" _
And Cells(cell.Row, c(i) + 97) = "x" Then
cell.Value = Cells(9, c(i) + 97)
End If
Next cell
Next i

By the way, I have taken the J and K assignments out of the loop as there is
no need to repeatedly read them.

Also, as written, you would get a Subscript out of range error, as the
expression:
For i = 0 To 5
calls for 6 values and your c array only comprises 5 values.

I should qualify this reply as I have not endeavoured to understand what
you are doing!


---
Regards,
Norman





"hotherps " wrote in message
...
When this code runs it starts to assign values in the array if the
conditions are true, but if the statements avaluate to false it moves
to the next number in the array. Basically it is jumbling up my
results.

Is there a way to tell the array to evaluate each number across the
enitre named range before moving on to the next number? Thanks


For Each cell In range("G11:I125")
c = Array(5,4,3,2,1)
For i = 0 To 5
J = 356
K = 305
If Cells(J, c(i)).Value - 1 = Cells(K, c(i)) And cell.Value "" And
Cells(cell.Row, c(i) + 97) = "x" Then _
cell.Value = Cells(9, c(i) + 97)
Next i
Next


---
Message posted from http://www.ExcelForum.com/




hotherps[_89_]

Array Question
 
Thanks Norman, that did it

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 01:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com