Premise: I am automating a manual data entry process into a terminal emulation product (BlueZone) using VBA. As a front-end user I have limited commands and lift data from the screen (with a copy screen and paste into Excel) to make determinations and stop the run if an error is encountered. The data is related to warehouse inventory and there are compliance issues - so it is important there are checks to guarantee integrity.
I currently have a working loop, but I need it to iterate every 10 rows. In other words, I need it to:
1) Navigate to the associated emulation screen
2) Enter the header data
3) Enter 10 products with adjustment amounts - start at row 5
4) Commit the entry
5) Begin again at (1) at row 15
I have attempted without success:
For i = 1 to 3000 Step 10 '3000 same range defined as object in current for each
Screenshots of the system and user entry form:
Sub IISAB_DuuEet()
Dim bzhao As Object
Set bzhao = CreateObject("BZWhll.WhllObj")
bzhao.Connect ""
Dim myLoc, Prod, Adj_Dir, Adj_Qty As Variant
Dim RC As String 'Reason Code
Dim Julian As Integer 'Julian Date
Dim myRange As Range
Set myRange = Worksheets("Inventory_Adjustment").Range("A5:A3000") 'Entire range
RC = Sheets("Inventory_Adjustment").Range("A2").Value
Julian = Sheets("Inventory_Adjustment").Range("B2").Value
'--------------------------------------BLOCK 1----------------------------------------------
'********BLOCK 1 must occur only when i=1 of 10********'
'Navigar a IISAB y preparate
bzhao.SendKey "<PF3>"
bzhao.Wait 0.2
bzhao.SendKey "IISAB"
bzhao.Wait 0.2
bzhao.SendKey "<ENTER>"
bzhao.Wait 0.2
bzhao.SendKey "A"
bzhao.Wait 0.2
bzhao.SendKey RC
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Julian
bzhao.Wait 0.2
bzhao.SendKey "<TAB><TAB><TAB><TAB>"
'--------------------------------------BLOCK 2----------------------------------------------
'********BLOCK 2 must occur for all i = 1 to 10********'
'Begin L00P on location>Prod>(+/-)>Qty 10x
For Each myLoc In myRange
'Si hay un blanco ya
If myLoc = "" Then
Exit For
End If
Prod = myLoc.Offset(0, 1).Value
Adj_Dir = myLoc.Offset(0, 2).Value
Adj_Qty = myLoc.Offset(0, 3).Value
'Begin adjusts
bzhao.SendKey myLoc
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.5
'Check product
bzhao.Copy 32
Range("I1").Select
ActiveSheet.Paste
bzhao.Wait 0.2
'First flag "ERROR" on screen
If Range("D1").Value = "ERROR" Then
myLoc.Offset(0, 4).Value = "ERROR"
MsgBox ("Error")
Exit For
End If
'Second flag product match what populated for the location
If myLoc.Offset(0, 6).Value = "PASS" Then
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Adj_Qty
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Adj_Dir
bzhao.Wait 0.2
myLoc.Offset(0, 4).Value = "ENTERED"
Else 'ERROR, bomb out
myLoc.Offset(0, 4).Value = "ERROR"
MsgBox ("Error")
Exit For
End If
Next myLoc
'After 10th iteration -
'1) Commit inventory adjustments
'2) Start i=1 again with Block 1 and enter 10 more products
'--------------------------------------------------------------------------------------
End Sub
Attempt with Step 10 - I removed the working For Each.
Sub IISAB_DuuEet2()
Dim bzhao As Object
Set bzhao = CreateObject("BZWhll.WhllObj")
bzhao.Connect ""
Dim myLoc, Prod, Adj_Dir, Adj_Qty As Variant
Dim RC As String 'Reason Code
Dim Julian As Integer 'Julian Date
Dim myRange As Range
Set myRange = Worksheets("Inventory_Adjustment").Range("A5:A3000") 'Entire range
RC = Sheets("Inventory_Adjustment").Range("A2").Value
Julian = Sheets("Inventory_Adjustment").Range("B2").Value
'--------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------
'Begin L00P on location>Prod>(+/-)>Qty 10x
For i = 1 To 3000 Step 10
myLoc = Cells(i, 0).Value 'DEBUG object define error
'Si hay un blanco ya
If myLoc = "" Then
Exit For
End If
If i = 1 Then 'Enter screen info AND first line
bzhao.SendKey "<PF3>"
bzhao.Wait 0.2
bzhao.SendKey "IISAB"
bzhao.Wait 0.2
bzhao.SendKey "<ENTER>"
bzhao.Wait 0.2
bzhao.SendKey "A"
bzhao.Wait 0.2
bzhao.SendKey RC
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Julian
bzhao.Wait 0.2
bzhao.SendKey "<TAB><TAB><TAB><TAB>"
Prod = myLoc.Offset(0, 1).Value
Adj_Dir = myLoc.Offset(0, 2).Value
Adj_Qty = myLoc.Offset(0, 3).Value
'Begin adjusts
bzhao.SendKey myLoc
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.5
'Check product
bzhao.Copy 32
Range("I1").Select
ActiveSheet.Paste
bzhao.Wait 0.2
'First flag "ERROR" on screen
If Range("G2").Value = "ERROR" Then
myLoc.Offset(0, 4).Value = "ERROR"
MsgBox ("Error")
Exit For
End If
'Second flag product match what populated for the location
If myLoc.Offset(0, 6).Value = "PASS" Then
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Adj_Qty
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Adj_Dir
bzhao.Wait 0.2
myLoc.Offset(0, 4).Value = "ENTERED"
Else 'ERROR, bomb out
myLoc.Offset(0, 4).Value = "ERROR"
MsgBox ("Error")
Exit For
End If
End If 'end i=1 if
Prod = myLoc.Offset(0, 1).Value
Adj_Dir = myLoc.Offset(0, 2).Value
Adj_Qty = myLoc.Offset(0, 3).Value
'Begin adjusts
bzhao.SendKey myLoc
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.5
'Check product
bzhao.Copy 32
Range("I1").Select
ActiveSheet.Paste
bzhao.Wait 0.2
'First flag "ERROR" on screen
If Range("G2").Value = "ERROR" Then
myLoc.Offset(0, 4).Value = "ERROR"
MsgBox ("Error")
Exit For
End If
'Second flag product match what populated for the location
If myLoc.Offset(0, 6).Value = "PASS" Then
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Adj_Qty
bzhao.Wait 0.2
bzhao.SendKey "<TAB>"
bzhao.Wait 0.2
bzhao.SendKey Adj_Dir
bzhao.Wait 0.2
myLoc.Offset(0, 4).Value = "ENTERED"
Else 'ERROR, bomb out
myLoc.Offset(0, 4).Value = "ERROR"
MsgBox ("Error")
Exit For
End If
Next i
'--------------------------------------------------------------------------------------
End Sub


I was able to solve the problem by:
(1) Sheet formula to create 1-10 counts in column F
(2) Link with vlookup to the screen position in column H
(3) Column G interprets the screenshots
(3) If statements within the For Each to accommodate the iterations every 10 rows
Not the most eloquent, but the following code executed without incident: