Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Reference sheets named by DAY

How do I reference the sheet named 20 (for the day of the month), then tomorrow the With Sheets("20") will be With Sheets("21")?

Sub Macro1()

With Sheets("20")
'.do stuff
End With


End Sub

On the worksheet in a cell =Today() and then custom formatted "d" returns 20.
Tomorrow I presume it will return 21.

How do I make that happen in the code?

Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Reference sheets named by DAY

Hi Howard,

Am Tue, 20 Jan 2015 03:04:49 -0800 (PST) schrieb L. Howard:

How do I reference the sheet named 20 (for the day of the month), then tomorrow the With Sheets("20") will be With Sheets("21")?


try:

With Sheets(CStr(Day(Date)))
'Do some stuff
End With


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Reference sheets named by DAY


try:

With Sheets(CStr(Day(Date)))
'Do some stuff
End With


Regards
Claus B.\


Thanks, Claus.

Hmmm, new stuff for me. I find this as to describe CStr but very little on examples.

CStr Converts an expression to string data type


Is there a short "how it works" or is it best understood to "go to school" on the function?

Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Reference sheets named by DAY

Hi Howard,

Am Tue, 20 Jan 2015 04:12:33 -0800 (PST) schrieb L. Howard:

CStr Converts an expression to string data type


Sheets(20) is the 20th sheet in the workbook.
Sheets("20") is your sheet named by day.
Day(Date) is a numeric value and would refer to the 20th sheet.
So you have to convert Day(Date) to string.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Reference sheets named by DAY

On Tuesday, January 20, 2015 at 4:20:13 AM UTC-8, Claus Busch wrote:
Hi Howard,

Am Tue, 20 Jan 2015 04:12:33 -0800 (PST) schrieb L. Howard:

CStr Converts an expression to string data type


Sheets(20) is the 20th sheet in the workbook.
Sheets("20") is your sheet named by day.
Day(Date) is a numeric value and would refer to the 20th sheet.
So you have to convert Day(Date) to string.


Regards
Claus B.
--


Okay, thanks. Along with that and this that I found, should keep me off the streets for awhile!


CStr and Date

The Date type always contains both date and time information. For purposes of type conversion, Visual Basic considers 1/1/0001 (January 1 of the year 1) to be a neutral value for the date, and 00:00:00 (midnight) to be a neutral value for the time. CStr does not include neutral values in the resulting string. For example, if you convert #January 1, 0001 9:30:00# to a string, the result is "9:30:00 AM"; the date information is suppressed. However, the date information is still present in the original Date value and can be recovered with functions such as DatePart.

Howard


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Reference sheets named by DAY

Hi Howard,

Am Tue, 20 Jan 2015 04:27:18 -0800 (PST) schrieb L. Howard:

CStr and Date

The Date type always contains both date and time information. For purposes of type conversion, Visual Basic considers 1/1/0001 (January 1 of the year 1) to be a neutral value for the date, and 00:00:00 (midnight) to be a neutral value for the time. CStr does not include neutral values in the resulting string. For example, if you convert #January 1, 0001 9:30:00# to a string, the result is "9:30:00 AM"; the date information is suppressed. However, the date information is still present in the original Date value and can be recovered with functions such as DatePart.


Dim myDate As Date

myDate = #1/1/2001 9:30:00 AM#

MsgBox CStr(myDate)

The result is: "01.01.2001 09:30:00"


Dim myDate As Double

myDate = #1/1/2001 9:30:00 AM#

MsgBox CStr(myDate)

The result is:"36892.3958333333


Dim myDate As Double

myDate = #1/1/2001 9:30:00 AM#

MsgBox CStr(Day(myDate))

The result = "1" as well with dimension date and double


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Reference sheets named by DAY


Dim myDate As Date

myDate = #1/1/2001 9:30:00 AM#

MsgBox CStr(myDate)

The result is: "01.01.2001 09:30:00"


Dim myDate As Double

myDate = #1/1/2001 9:30:00 AM#

MsgBox CStr(myDate)

The result is:"36892.3958333333


Dim myDate As Double

myDate = #1/1/2001 9:30:00 AM#

MsgBox CStr(Day(myDate))

The result = "1" as well with dimension date and double


Regards
Claus B.



Now that's a plateful!

Howard
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Reference sheets named by DAY

Not meaning to ad to your already "plate full", but I thought I'd share
a concept here that fits the topic.

The project is a single-file daily scheduler that uses a sheet template
for each day of a month. The task of the project is to 'schedule'
fitness instructors at a gym for assignments during their shift.

There are 12 workbooks named for a fiscal period of 1 calendar year.

The template workbook has 31 copies of the daily scheduler template
sheet.

Each day when the file is opened this happens...

Sub Auto_Open()
Dim wksToday As Worksheet
InitGlobals '//initialize global variables

'Setup ThisWorkbook.Name to match GymID
If Not InStr(ThisWorkbbok.Name, gsThisGym) Then
ThisWorkbook.SaveAs gsAppPath & gsThisGym _
& Format(Month(Date()), "Mmm")
& ThisWorkbook.Name
End If

Set wksToday = Sheets(Day(Date())
With wksToday: .Visible = True: .Activate: End With
InitDailyWks '//setup default sheet info
End Sub

...which only activates the appropriate sheet on/for days the gym is
open.

The InitDailyWks routine inserts the date field on the template with a
long date format ("day Month dd, yyyy"), and fills in the gym location
details.

The InitGlobals routine loads values into global scope variables used
by a project. This and the variable declarations reside in the same
module as the AutoMacros, replacing the Workbook_Open event...

Sub InitGlobals()
gsAppPath = ThisWorkbook.Path & "\"
If Not bNameExists("GymID") Then Setup_ThisGym
gsThisGym = "GymID" _
& Mid(ThisWorkbook.Names("GymID").RefersTo, 2) & "_"
End Sub


Function bNameExists(sName$, Optional Wks As Worksheet) As Boolean
' Checks if sName exists in Wks
' Arguments:
' sName The defined name to check for
' Wks A ref to the Wkb or Wks being checked
' Returns:
' True if name exists

Dim x As Object
If Wks Is Nothing Then Set Wks = ActiveSheet
On Error Resume Next
Set x = Wks.Names(sName): bNameExists = (Err = 0)
End Function

...where InitGlobals also validates globals if their values aren't set.

The Setup_ThisGym routine creates local scope defined names for each
template sheet for "GymID" and "GymInfo". (This info is provided by the
user at 1st startup only) The names are local scope so the head office
can merge daily sheets for each month in a consolidation file for the
year, without raising name conflicts. Also, each gym has its own sheet
in the merged file, and each month gets a row in an outlined area for
that month.

Fortunately, this client only has 2 locations and so managing things
this way works for them. I propose a different approach if they add
more locations whereby the project converts to an addin that uses a
single daily scheduker worksheet template and starts new workbooks
based on month name for any calendar year. This would greatly simplify
ongoing project management/maintenance. Also, the distributed addin
won't require any head office code, making that a separate addin that
can easily be made a 'plugin' to the main addin installed at head
office if it needs its own scheduler. This, of course, changes the
project structure so it's no longer a single-file solution!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
List Sheets excluding sheets named ***-A Dolphinv4 Excel Discussion (Misc queries) 1 December 15th 07 09:29 AM
Print sheets by "All Sheets in workbook, EXCEPT for specific named sheets". Possible? Corey Excel Programming 2 December 11th 06 01:35 AM
Macro for filter on protected workbook that works for all sheets, no matter what sheets are named? StargateFanFromWork[_3_] Excel Programming 6 January 26th 06 06:31 PM
Named Reference Dave New Users to Excel 2 December 17th 05 08:20 AM
Reference a named range John M.[_3_] Excel Programming 2 October 8th 05 07:42 AM


All times are GMT +1. The time now is 06:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"