![]() |
vba if and goto statements
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 |
vba if and goto statements
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 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 |
vba if and goto statements
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 "bigjim" wrote in message ... 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 |
vba if and goto statements
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 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 |
All times are GMT +1. The time now is 05:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com