Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign a worksheet name to a variable


Hi,

Advice / help /code would be greatly appreciated.

I need to figure out how to assign the name of a worksheet to
variable. My situation is:
I have an combo box containing a list of year's, when a year i
selected a new worksheet is created and renamed to the year selected.
userform containing inputboxes is then used to enter dates onto the ne
sheet.

I need to figure out a way of ensuring only certain dates are entere
into certain sheets. (eg Only dates in 2005 can be entered into th
2005 sheet, etc etc)

The only way I have thought of doing this, (before the code fires tha
enters the dates onto the sheet) is to compare whatever date the use
wants to enter (in the form of the inputbox) against the name of th
spreadheet, I dont know how to do this, I assume that the workshee
name has be assigned to a variable before this can happen?

I would really appreciate any input /help.
Thanks
Be

--
benjammin
-----------------------------------------------------------------------
benjammind's Profile: http://www.excelforum.com/member.php...fo&userid=1821
View this thread: http://www.excelforum.com/showthread.php?threadid=38487

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Assign a worksheet name to a variable

This works if everything is a date (place it in the worksheet module)
Errors out if cell is text, or sheet name not equal to a year (text or
numeric)

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Integer, y As Double

x = Year(Target)
y = CDbl(ActiveSheet.Name)
If x = y Then
MsgBox "OK"
Else
MsgBox "Wrong Year"
Application.Undo

End If
End If
End Sub



--
steveB

Remove "AYN" from email to respond
"benjammind" wrote
in message ...

Hi,

Advice / help /code would be greatly appreciated.

I need to figure out how to assign the name of a worksheet to a
variable. My situation is:
I have an combo box containing a list of year's, when a year is
selected a new worksheet is created and renamed to the year selected. A
userform containing inputboxes is then used to enter dates onto the new
sheet.

I need to figure out a way of ensuring only certain dates are entered
into certain sheets. (eg Only dates in 2005 can be entered into the
2005 sheet, etc etc)

The only way I have thought of doing this, (before the code fires that
enters the dates onto the sheet) is to compare whatever date the user
wants to enter (in the form of the inputbox) against the name of the
spreadheet, I dont know how to do this, I assume that the worksheet
name has be assigned to a variable before this can happen?

I would really appreciate any input /help.
Thanks
Ben


--
benjammind
------------------------------------------------------------------------
benjammind's Profile:
http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=384877



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Assign a worksheet name to a variable

Is the sheet just created the activesheet now? If so, you could simply use
code like##


If Year(CLng(TextBox1.Text)) = activesheet.name then
'OK
Else
'Not OK
End If

--
HTH

Bob Phillips

"benjammind" wrote
in message ...

Hi,

Advice / help /code would be greatly appreciated.

I need to figure out how to assign the name of a worksheet to a
variable. My situation is:
I have an combo box containing a list of year's, when a year is
selected a new worksheet is created and renamed to the year selected. A
userform containing inputboxes is then used to enter dates onto the new
sheet.

I need to figure out a way of ensuring only certain dates are entered
into certain sheets. (eg Only dates in 2005 can be entered into the
2005 sheet, etc etc)

The only way I have thought of doing this, (before the code fires that
enters the dates onto the sheet) is to compare whatever date the user
wants to enter (in the form of the inputbox) against the name of the
spreadheet, I dont know how to do this, I assume that the worksheet
name has be assigned to a variable before this can happen?

I would really appreciate any input /help.
Thanks
Ben


--
benjammind
------------------------------------------------------------------------
benjammind's Profile:

http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=384877



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign a worksheet name to a variable


Hello Bob,
Yes it is the activesheet, many thanks for your reponse. Another point
of view is most helpful!

Ben


--
benjammind
------------------------------------------------------------------------
benjammind's Profile: http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=384877

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
Assign value to a variable name Gnarlodious Excel Discussion (Misc queries) 2 August 20th 06 07:10 AM
Assign value to variable rroach Excel Discussion (Misc queries) 1 July 13th 05 05:24 AM
Variable VB to assign new sheet name Kevin M Excel Worksheet Functions 0 June 17th 05 12:15 AM
Add new worksheet and assign it to an object variable? Thief_ Excel Programming 2 April 4th 05 07:21 AM
assign variable Tim Excel Programming 10 October 1st 04 07:33 PM


All times are GMT +1. The time now is 04:10 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"