PC Review


Reply
Thread Tools Rate Thread

vba if and goto statements

 
 
bigjim
Guest
Posts: n/a
 
      16th Jan 2009
I'm using Excell 2003 and trying to write a sub that does one thing if a cell
"g43" contains the words "2 stage" then go to cell "b635" and end the sub.
If not, I want it to open another worksheet in the same workbook. Here is my
code. No matter what is in g43, it goes to the new worksheet:

If Range("g38") = "2 stage" Then GoTo line1 Else GoTo line2

line1: Range("b635").Select
GoTo Lastline


line2:

Sheets("Encana Blend W WS").Visible = True
ActiveWorkbook.Sheets("Encana Blend W WS").Unprotect Password:="b"
Application.Goto ActiveWorkbook.Sheets("Encana Blend W WS").Cells(3)
ActiveWorkbook.Sheets("Encana Blend W WS").Protect Password:="b"
Sheets("Ticket Wizard").Visible = False
Lastline:

End Sub
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      17th Jan 2009
try it this standard way

if range("g43").value="2 stage" then
range("b635").select
exit sub
else
'goto other sheet where you did NOT do anything???
' you may/may not have to unhide or unprotect to do something???
end if


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"bigjim" <(E-Mail Removed)> wrote in message
news:322ED6FB-C283-4FFE-99F9-(E-Mail Removed)...
> I'm using Excell 2003 and trying to write a sub that does one thing if a
> cell
> "g43" contains the words "2 stage" then go to cell "b635" and end the sub.
> If not, I want it to open another worksheet in the same workbook. Here is
> my
> code. No matter what is in g43, it goes to the new worksheet:
>
> If Range("g38") = "2 stage" Then GoTo line1 Else GoTo line2
>
> line1: Range("b635").Select
> GoTo Lastline
>
>
> line2:
>
> Sheets("Encana Blend W WS").Visible = True
> ActiveWorkbook.Sheets("Encana Blend W WS").Unprotect Password:="b"
> Application.Goto ActiveWorkbook.Sheets("Encana Blend W WS").Cells(3)
> ActiveWorkbook.Sheets("Encana Blend W WS").Protect Password:="b"
> Sheets("Ticket Wizard").Visible = False
> Lastline:
>
> End Sub


 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      17th Jan 2009
Hi

This should do it:

Sub AAA()
If Range("g38").Value = "2 stage" Then
Range("b635").Select
Else
Sheets("Encana Blend W WS").Visible = True
ActiveWorkbook.Sheets("Encana Blend W WS").Unprotect Password:="b"
Application.Goto ActiveWorkbook.Sheets("Encana Blend W WS").Cells
(3)
ActiveWorkbook.Sheets("Encana Blend W WS").Protect Password:="b"
Sheets("Ticket Wizard").Visible = False
End If
End Sub


Regards,
Per

On 16 Jan., 23:38, bigjim <big...@discussions.microsoft.com> wrote:
> I'm using Excell 2003 and trying to write a sub that does one thing if a cell
> "g43" contains the words "2 stage" then go to cell "b635" and end the sub.. *
> If not, I want it to open another worksheet in the same workbook. *Hereis my
> code. *No matter what is in g43, it goes to the new worksheet:
>
> If Range("g38") = "2 stage" Then GoTo line1 Else GoTo line2
>
> line1: *Range("b635").Select
> GoTo Lastline
>
> line2:
>
> *Sheets("Encana Blend W WS").Visible = True
> ActiveWorkbook.Sheets("Encana Blend W WS").Unprotect Password:="b"
> Application.Goto ActiveWorkbook.Sheets("Encana Blend W WS").Cells(3)
> ActiveWorkbook.Sheets("Encana Blend W WS").Protect Password:="b"
> Sheets("Ticket Wizard").Visible = False
> Lastline:
>
> End Sub


 
Reply With Quote
 
bigjim
Guest
Posts: n/a
 
      17th Jan 2009
thank you so much. I'll give it a try.

Jim

"Don Guillett" wrote:

> try it this standard way
>
> if range("g43").value="2 stage" then
> range("b635").select
> exit sub
> else
> 'goto other sheet where you did NOT do anything???
> ' you may/may not have to unhide or unprotect to do something???
> end if
>
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "bigjim" <(E-Mail Removed)> wrote in message
> news:322ED6FB-C283-4FFE-99F9-(E-Mail Removed)...
> > I'm using Excell 2003 and trying to write a sub that does one thing if a
> > cell
> > "g43" contains the words "2 stage" then go to cell "b635" and end the sub.
> > If not, I want it to open another worksheet in the same workbook. Here is
> > my
> > code. No matter what is in g43, it goes to the new worksheet:
> >
> > If Range("g38") = "2 stage" Then GoTo line1 Else GoTo line2
> >
> > line1: Range("b635").Select
> > GoTo Lastline
> >
> >
> > line2:
> >
> > Sheets("Encana Blend W WS").Visible = True
> > ActiveWorkbook.Sheets("Encana Blend W WS").Unprotect Password:="b"
> > Application.Goto ActiveWorkbook.Sheets("Encana Blend W WS").Cells(3)
> > ActiveWorkbook.Sheets("Encana Blend W WS").Protect Password:="b"
> > Sheets("Ticket Wizard").Visible = False
> > Lastline:
> >
> > End Sub

>
>

 
Reply With Quote
 
bigjim
Guest
Posts: n/a
 
      17th Jan 2009
Thank you so much. I'll give this a try.

Jim

"Per Jessen" wrote:

> Hi
>
> This should do it:
>
> Sub AAA()
> If Range("g38").Value = "2 stage" Then
> Range("b635").Select
> Else
> Sheets("Encana Blend W WS").Visible = True
> ActiveWorkbook.Sheets("Encana Blend W WS").Unprotect Password:="b"
> Application.Goto ActiveWorkbook.Sheets("Encana Blend W WS").Cells
> (3)
> ActiveWorkbook.Sheets("Encana Blend W WS").Protect Password:="b"
> Sheets("Ticket Wizard").Visible = False
> End If
> End Sub
>
>
> Regards,
> Per
>
> On 16 Jan., 23:38, bigjim <big...@discussions.microsoft.com> wrote:
> > I'm using Excell 2003 and trying to write a sub that does one thing if a cell
> > "g43" contains the words "2 stage" then go to cell "b635" and end the sub..
> > If not, I want it to open another worksheet in the same workbook. Here is my
> > code. No matter what is in g43, it goes to the new worksheet:
> >
> > If Range("g38") = "2 stage" Then GoTo line1 Else GoTo line2
> >
> > line1: Range("b635").Select
> > GoTo Lastline
> >
> > line2:
> >
> > Sheets("Encana Blend W WS").Visible = True
> > ActiveWorkbook.Sheets("Encana Blend W WS").Unprotect Password:="b"
> > Application.Goto ActiveWorkbook.Sheets("Encana Blend W WS").Cells(3)
> > ActiveWorkbook.Sheets("Encana Blend W WS").Protect Password:="b"
> > Sheets("Ticket Wizard").Visible = False
> > Lastline:
> >
> > End Sub

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Just replace BUS!="usb*", GOTO="libgphoto2_rules_end" with "SUBSYSTEM!="usb_device", GOTO="libgphoto2_rules_end" luisortizhome@yahoo.com Windows Vista General Discussion 3 10th Sep 2007 07:46 AM
On Error GoTo Statements not working =?Utf-8?B?S2Vu?= Microsoft Access Form Coding 2 23rd Nov 2006 06:54 PM
On Error Goto doesn't goto =?Utf-8?B?UGF1bA==?= Microsoft Excel Programming 1 15th Oct 2004 03:51 PM
On Error Goto doesn't goto =?Utf-8?B?UGF1bA==?= Microsoft Excel Programming 0 15th Oct 2004 03:05 PM
two field on the form goto another field then goto table M. Shahab Microsoft Access 0 14th Jul 2003 09:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:16 PM.