ExcelBanter

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

mvyvoda

For Each Array Question
 
Greeting,

I'm trying to use an array to complete a task. The following code is what I
have thus far, but get an error on the 2nd line (OSRCount is the array). I
need to make this loop work for each item in the arraym but don't really know
how to do that.

-----Function--------------------------
For Each OSRCount In OSRList
Do While RowEnd < RowEnd + (2 * OSRCount / 3)
Range(Cells(RowStart, ColumnStart), Cells(RowEnd, ColumnStart +
2)).Select
Selection.Cut
Range(Cells(RowStart - OSRCount / 3, ColumnStart + 5),
Cells(RowStart - OSRCount / 3, ColumnStart + 5)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
RowStart = RowStart + Round(2 * (OSRCount / 3))
RowEnd = RowEnd + Round(2 * (OSRCount / 3))
ColumnStart = ColumnStart + 4
Exit For
Loop
Next
------- Definition of Array --------------------------------
OSRList = Array("BS", "CK", "HS", "IT", "JD", "JW", "KC", "KF", "MG",
"MM", "SM", "TS", "VD")
For Each OSRCount In OSRList
OSRCount = Application.CountIf(Sheets("ALLACCT").Range("B:B") ,
OSRList)
Exit For
Next
--------------------------------

Any help would be really appreciated!,
-m

Bob Phillips

For Each Array Question
 
You can loop through an array like this

For i = LBound(OSRCount) To UBound(OSRCount)
msgbox OSRCount(i)
Next i

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"mvyvoda" wrote in message
...
Greeting,

I'm trying to use an array to complete a task. The following code is what

I
have thus far, but get an error on the 2nd line (OSRCount is the array). I
need to make this loop work for each item in the arraym but don't really

know
how to do that.

-----Function--------------------------
For Each OSRCount In OSRList
Do While RowEnd < RowEnd + (2 * OSRCount / 3)
Range(Cells(RowStart, ColumnStart), Cells(RowEnd, ColumnStart

+
2)).Select
Selection.Cut
Range(Cells(RowStart - OSRCount / 3, ColumnStart + 5),
Cells(RowStart - OSRCount / 3, ColumnStart + 5)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
RowStart = RowStart + Round(2 * (OSRCount / 3))
RowEnd = RowEnd + Round(2 * (OSRCount / 3))
ColumnStart = ColumnStart + 4
Exit For
Loop
Next
------- Definition of Array --------------------------------
OSRList = Array("BS", "CK", "HS", "IT", "JD", "JW", "KC", "KF", "MG",
"MM", "SM", "TS", "VD")
For Each OSRCount In OSRList
OSRCount = Application.CountIf(Sheets("ALLACCT").Range("B:B") ,
OSRList)
Exit For
Next
--------------------------------

Any help would be really appreciated!,
-m





All times are GMT +1. The time now is 04:39 AM.

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