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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move to the next cell in the loop if blank data is pulled from Screen

Status
Not open for further replies.

Gatorsbucs

Technical User
Jul 23, 2009
7
US
Hello,

Was wondering if someone might be able to help with some EB code? My macro currently grabs 10 lines of data (For Y = 10 to 19) from 5 screens (For P = 1 to 5), PF8 forwards to the next page if there is more data. This runs in a loop using data in column B (X) until it is either blank or reaches a count of 200. My issue is: the data in cell B10 may have less data to pull than that of cell B5. It may only have 1 page of data to
pull vs 5 (For P = 1 to 5) and may also only have 1 line of data. What happens in these cases is the code continues to pull the data. When there is no longer any actual data on
the screen it pulls the "blank" data and populates blanks in the following rows of my excel spreadsheet. Since there are no additional pages to pull it continues to pull the
original line of data. So I end up with 1 row of data followed by 9 blank rows, then on row 10 I get the original line of data. What I think I need to do is put in some sort
of “if Trim(A2) = "" then" ........what I need it to do when it comes to a blank area on the screen is move on to the next cell in column B on not “End Sub” This is the part I can’t figure out.

Thanks
 

Global g_HostSettleTime%

Sub Main


Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions

g_HostSettleTime = 0001

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Dim xl As Object
Dim Workbook As Object
Set xl = CreateObject("xl.Application")
xl.Visible = True

Set Workbook = xl.Workbooks.Open("C:\Documents and Settings\rbarnett\Desktop\Macro Models\MODEL.xlsm")


For X = 3 to 200

If X < 200 Then
C = C + 1
End IF

With xl.Worksheets("METHOD")
R = 4
ID = .range("A" & 3)
MN = .range("B" & X)
End with


If MN = "" Then
Msgbox "MACRO IS COMPLETE"
Workbook.Save
xl.Quit
Exit Sub : End If


Sess0.Screen.Sendkeys("<HOME>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys(ID)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 07, 15
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys("x<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys("AOACMN")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys(MN)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys("x<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys("<PF11>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 09, 11
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys("x<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

For P = 1 to 5
For Y = 10 to 19

A2 = Sess0.Screen.GetString(Y, 05, 16)
Workbook.Worksheets("METHOD X-REF").Cells(R, C).Value = A2
R = R + 1

Next Y

Sess0.Screen.Sendkeys("<PF8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Next P

IF Y = 20 Then
Y = 10
End IF


Sess0.Screen.Sendkeys("<PF3>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<PF3>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)



Next X
End Sub

 
something like this

Code:
 if Trim(A2) = "" then goto here:



here:
next x
 
another way would have been to write it this way

Code:
 if Trim(A2) <> "" then
'your script goes here
end if

in other words, if the cell is not blank, then do something

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top