Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 38
Default Question on "On Error GoTo skip"

I have this routine in "TestBook.xls"


Sub check()
' I want to check if "data.csv" is open.
' Why statement "On Error GoTo skip1" works once only?
' I expected Range("L4:L10") = 0 if "data.csv" is not open
' Range("L4:L10") = 1 if "data.csv" is open
' Please help

Dim r As Long
For r = 4 To 10
On Error GoTo skip1
Windows("data.csv").Activate
GoTo skip2
skip1:
Windows("TestBook.xls").Activate
Cells(r, 12) = 0
GoTo skip3
skip2:
Windows("TestBook.xls").Activate
Cells(r, 12) = 1
skip3:
Next r
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,345
Default Question on "On Error GoTo skip"

I assume it is because you are using an object. Help says:

"On Error Resume Next Specifies that when a run-time error occurs, control
goes to the statement immediately following the statement where the error
occurred where execution continues. Use this form rather than On Error GoTo
when accessing objects."

And this seems to work:

Sub check()
' I want to check if "data.csv" is open.
' Why statement "On Error GoTo skip1" works once only?
' I expected Range("L4:L10") = 0 if "data.csv" is not open
' Range("L4:L10") = 1 if "data.csv" is open
' Please help

Dim r As Long
For r = 4 To 10
On Error Resume Next
Windows("data.csv").Activate
If Error = Error(9) Then GoTo skip1
GoTo skip2
skip1:
Windows("TestBook.xls").Activate
Cells(r, 12) = 0
GoTo skip3
skip2:
Windows("TestBook.xls").Activate
Cells(r, 12) = 1
skip3:
Next r
End Sub

--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"dan" wrote in message
news:dSThi.2428$Nw5.2090@trndny04...
I have this routine in "TestBook.xls"


Sub check()
' I want to check if "data.csv" is open.
' Why statement "On Error GoTo skip1" works once only?
' I expected Range("L4:L10") = 0 if "data.csv" is not open
' Range("L4:L10") = 1 if "data.csv" is open
' Please help

Dim r As Long
For r = 4 To 10
On Error GoTo skip1
Windows("data.csv").Activate
GoTo skip2
skip1:
Windows("TestBook.xls").Activate
Cells(r, 12) = 0
GoTo skip3
skip2:
Windows("TestBook.xls").Activate
Cells(r, 12) = 1
skip3:
Next r
End Sub





  #3   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 38
Default Question on "On Error GoTo skip"

Great Help!
Thank you very much, Sandy

"Sandy Mann" wrote in message
...
I assume it is because you are using an object. Help says:

"On Error Resume Next Specifies that when a run-time error occurs, control
goes to the statement immediately following the statement where the error
occurred where execution continues. Use this form rather than On Error
GoTo
when accessing objects."

And this seems to work:

Sub check()
' I want to check if "data.csv" is open.
' Why statement "On Error GoTo skip1" works once only?
' I expected Range("L4:L10") = 0 if "data.csv" is not open
' Range("L4:L10") = 1 if "data.csv" is open
' Please help

Dim r As Long
For r = 4 To 10
On Error Resume Next
Windows("data.csv").Activate
If Error = Error(9) Then GoTo skip1
GoTo skip2
skip1:
Windows("TestBook.xls").Activate
Cells(r, 12) = 0
GoTo skip3
skip2:
Windows("TestBook.xls").Activate
Cells(r, 12) = 1
skip3:
Next r
End Sub

--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"dan" wrote in message
news:dSThi.2428$Nw5.2090@trndny04...
I have this routine in "TestBook.xls"


Sub check()
' I want to check if "data.csv" is open.
' Why statement "On Error GoTo skip1" works once only?
' I expected Range("L4:L10") = 0 if "data.csv" is not open
' Range("L4:L10") = 1 if "data.csv" is open
' Please help

Dim r As Long
For r = 4 To 10
On Error GoTo skip1
Windows("data.csv").Activate
GoTo skip2
skip1:
Windows("TestBook.xls").Activate
Cells(r, 12) = 0
GoTo skip3
skip2:
Windows("TestBook.xls").Activate
Cells(r, 12) = 1
skip3:
Next r
End Sub







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Disk is Full" add-on question to "Can't reset last cell" post tod [email protected] Excel Discussion (Misc queries) 0 January 22nd 07 02:32 AM
Shortcut key for "Paste Options" and "Error Checking" buttons? johndog Excel Discussion (Misc queries) 1 October 6th 06 11:56 AM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
On Error GoTo skip needs help dan Excel Discussion (Misc queries) 2 April 24th 06 06:29 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"