Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default a slight syntax error...

A little refresher please...
I'm trying to make the user choose which sheet to enter data on by
selecting a 1 2 or 3.
In case someone renames or reorders the sheets, I don't want to refer
to those things. I do want to refer to the sheet in the format
Sheet4, Sheet7, or Sheet8.
Most of what I have here works fine until you get to the variable
assignment at the end.
Thanks in advance for what I'm sure will be a small syntax error on my
part.
Rob

Sub whichsheet()
Dim ws As Worksheet
Dim x As Integer, y As Integer
x = InputBox("1 2 or 3")
Select Case x
Case 1
y = 4
Case 2
y = 7
Case 3
y = 8
Case Else
End Select
ws = Sheet y '<--Here is where I get lost... How do I make the "y"
reference Sheet4?
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default a slight syntax error...

Sub picksheet()
n = Application.InputBox(prompt:="select a sheet:", Type:=1)
Sheets(n).Activate
End Sub
--
Gary''s Student - gsnu2007c


"okrob" wrote:

A little refresher please...
I'm trying to make the user choose which sheet to enter data on by
selecting a 1 2 or 3.
In case someone renames or reorders the sheets, I don't want to refer
to those things. I do want to refer to the sheet in the format
Sheet4, Sheet7, or Sheet8.
Most of what I have here works fine until you get to the variable
assignment at the end.
Thanks in advance for what I'm sure will be a small syntax error on my
part.
Rob

Sub whichsheet()
Dim ws As Worksheet
Dim x As Integer, y As Integer
x = InputBox("1 2 or 3")
Select Case x
Case 1
y = 4
Case 2
y = 7
Case 3
y = 8
Case Else
End Select
ws = Sheet y '<--Here is where I get lost... How do I make the "y"
reference Sheet4?
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default a slight syntax error...

Your code seems a little round about... How about this...

Sub whichsheet()
Dim ws As Worksheet
Dim x As Integer, y As Integer
x = InputBox("1 2 or 3")
Select Case x
Case 1
set ws = sheet4
Case 2
set ws = sheet7
Case 3
set ws = sheet8
Case Else
End Select

End Sub

note that the code is referencing the code name of the sheet and not the tab
name... if you want tab name then...

Sub whichsheet()
Dim ws As Worksheet
Dim x As Integer, y As Integer
x = InputBox("1 2 or 3")
Select Case x
Case 1
set ws = sheets("sheet4")
Case 2
set ws = sheets("sheet7")
Case 3
set ws = sheets("sheet8")
Case Else
End Select

End Sub
--
HTH...

Jim Thomlinson


"okrob" wrote:

A little refresher please...
I'm trying to make the user choose which sheet to enter data on by
selecting a 1 2 or 3.
In case someone renames or reorders the sheets, I don't want to refer
to those things. I do want to refer to the sheet in the format
Sheet4, Sheet7, or Sheet8.
Most of what I have here works fine until you get to the variable
assignment at the end.
Thanks in advance for what I'm sure will be a small syntax error on my
part.
Rob

Sub whichsheet()
Dim ws As Worksheet
Dim x As Integer, y As Integer
x = InputBox("1 2 or 3")
Select Case x
Case 1
y = 4
Case 2
y = 7
Case 3
y = 8
Case Else
End Select
ws = Sheet y '<--Here is where I get lost... How do I make the "y"
reference Sheet4?
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
runtime error: syntax error or access violation oucsester[_2_] Excel Programming 1 May 3rd 06 05:51 PM
runtime error: syntax error or access violation oucsester Excel Programming 0 May 3rd 06 02:22 PM
Slight Error in my Simple code Abode Excel Programming 1 March 23rd 06 06:33 PM
variable not declared error & syntax error G. Beard Excel Programming 1 October 6th 05 09:16 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


All times are GMT +1. The time now is 07:14 PM.

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"