Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble getting Macro to Loop 1

Status
Not open for further replies.

link99sbc

Technical User
Apr 8, 2009
141
US
I'm trying to get this macro to loop a specified
number of times. I tried some examples in Excel help
but none worked. I have over 40,000 rows on the
spreadsheet. I want it to loop 25 or 50 or maybe 100
times starting on the ActiveCell.

This code works fine (1 row at a time)

Sub Check()


ActiveCell.Offset(1, 0).Activate
Selection.Copy

Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System")
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
Set Field = System.ActiveSession.Screen.Area(3, 8, 3, 16)
Set Field1 = System.ActiveSession.Screen.Area(4, 75, 4, 78)
Set Field2 = System.ActiveSession.Screen.Area(4, 75, 4, 78)
Set Field3 = System.ActiveSession.Screen.Area(4, 75, 4, 78)
Set Field4 = System.ActiveSession.Screen.Area(4, 75, 4, 78)
Field.Select
Field.Delete
Field.Value = ActiveCell

SendKeys "%{TAB}"
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.MoveTo 3, 24
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("081")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
ActiveCell.Offset(0, 1) = Field1.Value

Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.MoveTo 3, 24
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("082")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
ActiveCell.Offset(0, 2) = Field2.Value

Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.MoveTo 3, 24
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("083")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
ActiveCell.Offset(0, 3) = Field3.Value

Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.MoveTo 3, 24
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("084")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
ActiveCell.Offset(0, 4) = Field4.Value




End Sub
 



have to adjust the counter
Code:
              select case iCol
                case <= 4
                   oScrn.PutString "08" & iCol, 3, 24
                case else
                   oScrn.PutString "09" & iCol[b]-4[/b], 3, 24
              end select

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Didn't like this. Freezes the workbook.
Did a step through and appears to freeze at the first loop.
[]
Sub Checks()
Dim Sessions As Object
Dim System As Object
Dim Sess0 As Object
Dim oScrn As Object

Dim lRowCount, lOff As Long, iCol As Integer

Set System = CreateObject("EXTRA.System")
Set Sess0 = System.ActiveSession
Set oScrn = Sess0.Screen

lRowCount = InputBox("How many rows to process?")
ActiveCell.Offset(1, 0).Activate

If lRowCount > 0 Then
Do While lOff <= lRowCount
oScrn.PutString ActiveCell.Offset(lOff, 0).Value, 3, 8 'acctnbr
For iCol = 1 To 8
Select Case iCol
Case Is <= 4
oScrn.PutString "08" & iCol, 3, 24
Case Else
oScrn.PutString "09" & iCol - 4, 3, 24
End Select
oScrn.MoveRelative 1, 1, 1
oScrn.SendKeys ("<Enter>")
Do Until oScrn.WaitForCursor(3, 24)
DoEvents
stops here---> Loop
ActiveCell.Offset(lOff, iCol) = _
oScrn.Area(4, 75, 4, 78).Value
Next
ActiveCell.Offset(lOff, iCol) = _
oScrn.Area(3, 34, 3, 63).Value
lOff = lOff + 1
Loop
End If


Set oScrn = Nothing
Set Sess0 = Nothing
Set System = Nothing
End Sub

 


Do Until oScrn.WaitForCursor(3, 24)
DoEvents
stops here---> Loop
this indicates that 3,24 is not getting the cursor back.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yep works fine
The cursor always goes home after enter "3,08"

Do Until oScrn.WaitForCursor(3, 08)
DoEvents
 
Skip, i tried to modify this for a different screen
but i can't figure out the case structure
 
sorry i forgot the code

lRowCount = InputBox("How many rows to process?")
ActiveCell.Offset(0, 0).Activate

If lRowCount > 0 Then
Do While lOff <= lRowCount

oScrn.PutString Left(ActiveCell.Offset(lOff, 0).Value, 3), 3, 5 'acctnbr
oScrn.PutString Right(ActiveCell.Offset(lOff, 0).Value, 4), 3, 9 'acctnbr

For iCol = 1 To 12
Select Case iCol

Case Is <= 4
oScrn.PutString "07/" & iCol, 4, 7
Case 0
oScrn.PutString "08/" & iCol - 4, 4, 7
Case Else
oScrn.PutString "09/" & iCol - 4, 4, 7

End Select
oScrn.MoveRelative 1, 1, 1
oScrn.SendKeys ("<PF8>")
Do While Sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
oScrn.SendKeys ("<Enter>")

Do While Sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
' Do Until oScrn.WaitForCursor(3, 8)
' DoEvents
' Loop

ActiveCell.Offset(lOff, iCol) = _
oScrn.Area(20, 74, 22, 78).Value

Next
ActiveCell.Offset(lOff, iCol) = _
oScrn.Area(3, 19, 3, 63).Value
lOff = lOff + 1
Loop
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top