From jbartow at winhaven.net Thu May 10 00:19:25 2018 From: jbartow at winhaven.net (John Bartow) Date: Thu, 10 May 2018 05:19:25 +0000 Subject: [Dba-office] Excel sheet tabs & reference to it Message-ID: I have a baseball roster, player stats and team stats. Each player gets a sheet with all of their stats per game. That sheet has the players name as the sheet tab name. At the end of each season all I have to do is type in the new player roster and everything works. Except the Tab names and because the sheets are references for the team totals, the tab names are in the totals function's reference. Is there some method of finding and replacing a word in the entire workbook - including the name of the sheet tabs? Or is there a method to reference the tab without using the tab's name? Thanks, John B From davidmcafee at gmail.com Thu May 10 01:22:55 2018 From: davidmcafee at gmail.com (David McAfee) Date: Thu, 10 May 2018 06:22:55 +0000 Subject: [Dba-office] Excel sheet tabs & reference to it In-Reply-To: References: Message-ID: Im half asleep right now, and dont have a computer in front of me, but i do know i have referenced worksheets by number instrad of name. It was something like WB.Sheet(1) or something lime that. I'll take a look when i get into the office if nobody has chimed in. On Wed, May 9, 2018, 10:20 PM John Bartow wrote: > I have a baseball roster, player stats and team stats. Each player gets a > sheet with all of their stats per game. That sheet has the players name as > the sheet tab name. > > At the end of each season all I have to do is type in the new player > roster and everything works. Except the Tab names and because the sheets > are references for the team totals, the tab names are in the totals > function's reference. > > Is there some method of finding and replacing a word in the entire > workbook - including the name of the sheet tabs? > > Or is there a method to reference the tab without using the tab's name? > > Thanks, > John B > > _______________________________________________ > Dba-office mailing list > Dba-office at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-office > From gustav at cactus.dk Thu May 10 02:12:33 2018 From: gustav at cactus.dk (Gustav Brock) Date: Thu, 10 May 2018 07:12:33 +0000 Subject: [Dba-office] Excel sheet tabs & reference to it In-Reply-To: References: Message-ID: Hi John It's not completely clear to me what you try to do, but I guess you can use these functions: ' Searches in the collection of worksheets of a workbook for ' a worksheet named Name or with a name starting with Name. ' Returns the index of the worksheet if found. ' Returns zero (0) if the worksheet name is empty or not found. ' ' To lookup the index of a worksheet with an exact name, use: ' ' Index = ThisWorkbook.Worksheets("Exact Name").Index ' ' 2017-09-08. Gustav Brock, Cactus Data ApS, CPH. ' Public Function WorksheetIndex( _ ByRef Workbook As Workbook, _ ByVal Name As String) _ As Integer Dim Worksheet As Excel.Worksheet Dim Index As Integer If Workbook Is Nothing Then ' Nothing to do. Exit Function ElseIf Name <> "" Then ' Loop worksheets. For Each Worksheet In Workbook.Worksheets If InStr(1, Worksheet.Name, Name, vbTextCompare) = 1 Then Index = Worksheet.Index Exit For End If Next End If Set Worksheet = Nothing WorksheetIndex = Index End Function ' Renames a worksheet in this workbook. ' ' 2017-02-26. Gustav Brock, Cactus Data ApS, CPH. ' Public Sub RenameWorksheet( _ ByVal Index As Variant, _ ByVal Name As String) CleanWorksheetName Name ThisWorkbook.Worksheets(Index).Name = Name End Sub ' Replaces characters in Name that are not allowed in a worksheet name. ' Truncates length of Name to MaxWorksheetNameLength. ' Returns the cleaned name by reference. ' ' 2017-02-26. Gustav Brock, Cactus Data ApS, CPH. ' Public Sub CleanWorksheetName(ByRef Name As String) ' No special error handling. On Error Resume Next ' Maximum length of a worksheet name in Excel. Const MaxWorksheetNameLength As Long = 31 ' String containing all not allowed characters. Const InvalidCharacters As String = "\/:*?<>[]" ' Character to replace not allowed characters. Const ReplaceCharacter As String * 1 = "-" ' Character ellipsis: ?. Const Ellipsis As String * 1 = "?" Dim Length As Integer Dim Position As Integer Dim Character As String Dim TrimmedName As String ' Strip doubled spaces. While InStr(Name, Space(2)) > 0 Name = Replace(Name, Space(2), Space(1)) Wend ' Strip leading and trailing spaces. TrimmedName = Trim(Name) ' Limit length of name. If Len(TrimmedName) > MaxWorksheetNameLength Then TrimmedName = Left(TrimmedName, MaxWorksheetNameLength - 1) & Ellipsis End If Length = Len(TrimmedName) For Position = 1 To Length Step 1 Character = Mid(TrimmedName, Position, 1) If InStr(InvalidCharacters, Character) > 0 Then Mid(TrimmedName, Position) = ReplaceCharacter End If Next ' Return cleaned name. Name = TrimmedName End Sub /gustav ________________________________________ Fra: dba-Tech p? vegne af John Bartow Sendt: 10. maj 2018 07:19:25 Til: DBA-Tech (dba-tech at databaseadvisors.com); DBA Office (dba-office at databaseadvisors.com) Emne: [dba-Tech] Excel sheet tabs & reference to it I have a baseball roster, player stats and team stats. Each player gets a sheet with all of their stats per game. That sheet has the players name as the sheet tab name. At the end of each season all I have to do is type in the new player roster and everything works. Except the Tab names and because the sheets are references for the team totals, the tab names are in the totals function's reference. Is there some method of finding and replacing a word in the entire workbook - including the name of the sheet tabs? Or is there a method to reference the tab without using the tab's name? Thanks, John B From ssharkins at gmail.com Thu May 10 06:11:53 2018 From: ssharkins at gmail.com (Susan Harkins) Date: Thu, 10 May 2018 07:11:53 -0400 Subject: [Dba-office] Excel sheet tabs & reference to it In-Reply-To: References: Message-ID: <01fb01d3e84f$b427e450$1c77acf0$@gmail.com> I don't think you can "find and replace" the sheet name, but you could do it programmatically. You kind of lost me though in the totals paragraph. Have you considered an info page where you enter the names and then let the sheets reflect what's in the info sheet? Then, you'd need to change only the data on that sheet? Am I following you okay -- or have I misunderstood the setup? Back to the sheet names though -- a sheet name can't directly reference cell contents, but I'm sure there's a workaround for that. It sounds like a reasonable thing to do, so I'm betting somebody's already thought of it. ? Susan H. I have a baseball roster, player stats and team stats. Each player gets a sheet with all of their stats per game. That sheet has the players name as the sheet tab name. At the end of each season all I have to do is type in the new player roster and everything works. Except the Tab names and because the sheets are references for the team totals, the tab names are in the totals function's reference. Is there some method of finding and replacing a word in the entire workbook - including the name of the sheet tabs? Or is there a method to reference the tab without using the tab's name? Thanks, John B _______________________________________________ Dba-office mailing list Dba-office at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-office From jbartow at winhaven.net Thu May 10 12:24:49 2018 From: jbartow at winhaven.net (John Bartow) Date: Thu, 10 May 2018 17:24:49 +0000 Subject: [Dba-office] Excel sheet tabs & reference to it In-Reply-To: <01fb01d3e84f$b427e450$1c77acf0$@gmail.com> References: <01fb01d3e84f$b427e450$1c77acf0$@gmail.com> Message-ID: Hi Susan, Today I open the spreadsheet and things work like I thought they should, e.g. I change a tab name and all references to that tab name in the sheets updated automatically. Last night that didn't seem to work. John B -----Original Message----- From: Dba-office On Behalf Of Susan Harkins Sent: Thursday, May 10, 2018 6:12 AM To: dba-office at databaseadvisors.com Subject: Re: [Dba-office] Excel sheet tabs & reference to it I don't think you can "find and replace" the sheet name, but you could do it programmatically. You kind of lost me though in the totals paragraph. Have you considered an info page where you enter the names and then let the sheets reflect what's in the info sheet? Then, you'd need to change only the data on that sheet? Am I following you okay -- or have I misunderstood the setup? Back to the sheet names though -- a sheet name can't directly reference cell contents, but I'm sure there's a workaround for that. It sounds like a reasonable thing to do, so I'm betting somebody's already thought of it. ? Susan H. I have a baseball roster, player stats and team stats. Each player gets a sheet with all of their stats per game. That sheet has the players name as the sheet tab name. At the end of each season all I have to do is type in the new player roster and everything works. Except the Tab names and because the sheets are references for the team totals, the tab names are in the totals function's reference. Is there some method of finding and replacing a word in the entire workbook - including the name of the sheet tabs? Or is there a method to reference the tab without using the tab's name? Thanks, John B _______________________________________________ Dba-office mailing list Dba-office at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-office _______________________________________________ Dba-office mailing list Dba-office at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-office From ssharkins at gmail.com Thu May 10 16:41:13 2018 From: ssharkins at gmail.com (Susan Harkins) Date: Thu, 10 May 2018 17:41:13 -0400 Subject: [Dba-office] Excel sheet tabs & reference to it In-Reply-To: References: <01fb01d3e84f$b427e450$1c77acf0$@gmail.com> Message-ID: <039301d3e8a7$9ee1ffb0$dca5ff10$@gmail.com> Yeah! Susan H. Hi Susan, Today I open the spreadsheet and things work like I thought they should, e.g. I change a tab name and all references to that tab name in the sheets updated automatically. Last night that didn't seem to work. John B -----Original Message----- From: Dba-office On Behalf Of Susan Harkins Sent: Thursday, May 10, 2018 6:12 AM To: dba-office at databaseadvisors.com Subject: Re: [Dba-office] Excel sheet tabs & reference to it I don't think you can "find and replace" the sheet name, but you could do it programmatically. You kind of lost me though in the totals paragraph. Have you considered an info page where you enter the names and then let the sheets reflect what's in the info sheet? Then, you'd need to change only the data on that sheet? Am I following you okay -- or have I misunderstood the setup? Back to the sheet names though -- a sheet name can't directly reference cell contents, but I'm sure there's a workaround for that. It sounds like a reasonable thing to do, so I'm betting somebody's already thought of it. ? Susan H. I have a baseball roster, player stats and team stats. Each player gets a sheet with all of their stats per game. That sheet has the players name as the sheet tab name. At the end of each season all I have to do is type in the new player roster and everything works. Except the Tab names and because the sheets are references for the team totals, the tab names are in the totals function's reference. Is there some method of finding and replacing a word in the entire workbook - including the name of the sheet tabs? Or is there a method to reference the tab without using the tab's name? Thanks, John B _______________________________________________ Dba-office mailing list Dba-office at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-office _______________________________________________ Dba-office mailing list Dba-office at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-office _______________________________________________ Dba-office mailing list Dba-office at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-office