Hello,
How do I use the GoTo so that I can Specify A line of Code to go to...
for example
Is this posible??![]()
On Error Goto Ln 43
Hello,
How do I use the GoTo so that I can Specify A line of Code to go to...
for example
Is this posible??![]()
On Error Goto Ln 43
Last edited by RBI; 10-30-2008 at 09:09 AM. Reason: mark as solved
Use the same code posted above, but then, where your reference is, you need to include the description. Example:
You can also do the same by using On Error GoTo imessedup![]()
Sub Test() If Date > Date Then GoTo imessedup MsgBox "Today is greater than today?!?" Exit Sub imessedup: MsgBox "Duh! Today can't be greater than today!" End Sub
HTH
Jason
Ya but does this work If the GoTO refers to a line that is before it
ex
You see the macro is just to open a file, search for a value then exit if it finds it, if not it closes and goes to the next but it's not working yet... The first Goto is to go back to the start if the filename can not be found t ofind the next file on the list, The secod Goto is to close the current file and go back to the list if the value being searchd for cannot be found... another problem is that i don't know if, when the "find" function doens't find anything is that an error?? cause if it's not then the second Goto won't work....![]()
Private Sub CommandButton4_Click() Dim Ump As String Dim Mns As String Dim Pth As String Dim Mnt As String Dim Fln As String Ump = Application.InputBox(Prompt:="Please Enter Cheque Date") Mnt = Month(Ump) Range("E54").Value = Mnt Mns = Range("F54").Value Pth = "Q:\CRS PAID FILE (Lai-Yin)\2008\" & Range("D42").Value & "_" & Mns Range("E86").Select Tst: Windows("Operating Leases 08").activate Do While ActiveCell <> "End" ActiveCell.Offset(1, 0).Select Fln = ActiveCell.Value ChDir Pth On Error GoTo Tst Workbooks.Open Filename:= _ Pth & "\" & Fln Range("F:F").Select On Error GoTo Nxt Selection.Find(What:="GE FLEET SERVICES", After:=ActiveCell, LookIn:=xlFormulas _ , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate Exit Sub Loop Exit Sub Nxt: ActiveWindow.Close GoTo Tst End Sub
Any Help on these issues is apprecieated
Last edited by RBI; 10-24-2008 at 03:46 PM.
I wasn't able to test it due to the amount of work that would be involved in replicating your situation, but try this code to see if it works:
Jason![]()
Private Sub CommandButton4_Click() Dim Ump As String Dim Mns As String Dim Pth As String Dim Mnt As String Dim Fln As String Dim Wkb As Workbook Dim Wks As Worksheet Dim Rng As Range Dim c As Range Dim i As Long Ump = Application.InputBox(Prompt:="Please Enter Cheque Date", Type:=1) Mnt = Month(Ump) Range("E54").Value = Mnt Mns = Range("F54").Value Pth = "Q:\CRS PAID FILE (Lai-Yin)\2008\" & Range("D42").Value & "_" & Mns Set Wks = ActiveSheet i = 87 With Wks While .Cells(i, 5) <> "End" Fln = .Cells(i, 5).Value ChDir Pth Set Wkb = Workbooks.Open(Filename:= _ Pth & "\" & Fln) If Not Wkb Is Nothing Then Set Rng = Wkb.ActiveSheet.Columns("F:F") Set c = Rng.Find(What:="GE FLEET SERVICES", After:=Rng.Resize(1, 1). _ Offset(0, -1), LookIn:=xlFormulas, LookAt:=xlWhole, _ SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _ SearchFormat:=False) If c Is Nothing Then Wkb.Close c.Activate Exit Sub End If i = i + 1 Wend End With End Sub
Last edited by jasoncw; 10-24-2008 at 07:31 PM.
In the code in post #3
change one line
![]()
Nxt: ActiveWindow.Close Resume Tst End Sub
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
Sorry Wrong Spot
Last edited by RBI; 10-27-2008 at 10:12 AM. Reason: Wrong Post
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks