Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Naming worksheets based on a cell value

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Naming worksheets based on a cell value

FatBear,

Your code is looping through all sheets and trying to give all of them the
same name.. try instead:

ActiveSheet.Name = Range("A1").Value


--
Hope that helps.

Vergel Adriano


"FatBear" wrote:

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Naming worksheets based on a cell value

Give this a try...

For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next ws

Assuming this code is in a standard module an unspecified range will point
to the active sheet. If the code is in a specific sheet then the range will
point to that sheet...
--
HTH...

Jim Thomlinson


"FatBear" wrote:

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Naming worksheets based on a cell value

Sorry my explanation shoud read "Assuming your code is in..." NOT "Assuming
this code is in..."
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Give this a try...

For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next ws

Assuming this code is in a standard module an unspecified range will point
to the active sheet. If the code is in a specific sheet then the range will
point to that sheet...
--
HTH...

Jim Thomlinson


"FatBear" wrote:

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Naming worksheets based on a cell value

But ws is never selected so the active sheet never changes. Your code will
rename only the active sheet and it will do it multiple times...
--
HTH...

Jim Thomlinson


"Vergel Adriano" wrote:

FatBear,

Your code is looping through all sheets and trying to give all of them the
same name.. try instead:

ActiveSheet.Name = Range("A1").Value


--
Hope that helps.

Vergel Adriano


"FatBear" wrote:

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Naming worksheets based on a cell value

Hi Jim,

My suggestion was actually not to loop and only rename the Activesheet one
time. I thought that's what the OP was trying to accomplish and missed the
part that he was doing a loop to add multiple worksheets <g



--
Hope that helps.

Vergel Adriano


"Jim Thomlinson" wrote:

But ws is never selected so the active sheet never changes. Your code will
rename only the active sheet and it will do it multiple times...
--
HTH...

Jim Thomlinson


"Vergel Adriano" wrote:

FatBear,

Your code is looping through all sheets and trying to give all of them the
same name.. try instead:

ActiveSheet.Name = Range("A1").Value


--
Hope that helps.

Vergel Adriano


"FatBear" wrote:

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Naming worksheets based on a cell value

I figured it had to be some kind of a goof. I have seen your code and it is
really good.
--
HTH...

Jim Thomlinson


"Vergel Adriano" wrote:

Hi Jim,

My suggestion was actually not to loop and only rename the Activesheet one
time. I thought that's what the OP was trying to accomplish and missed the
part that he was doing a loop to add multiple worksheets <g



--
Hope that helps.

Vergel Adriano


"Jim Thomlinson" wrote:

But ws is never selected so the active sheet never changes. Your code will
rename only the active sheet and it will do it multiple times...
--
HTH...

Jim Thomlinson


"Vergel Adriano" wrote:

FatBear,

Your code is looping through all sheets and trying to give all of them the
same name.. try instead:

ActiveSheet.Name = Range("A1").Value


--
Hope that helps.

Vergel Adriano


"FatBear" wrote:

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Naming worksheets based on a cell value

wow. thanks a lot for the kind comments Jim. :-)

Regards,
Vergel Adriano


"Jim Thomlinson" wrote:

I figured it had to be some kind of a goof. I have seen your code and it is
really good.
--
HTH...

Jim Thomlinson


"Vergel Adriano" wrote:

Hi Jim,

My suggestion was actually not to loop and only rename the Activesheet one
time. I thought that's what the OP was trying to accomplish and missed the
part that he was doing a loop to add multiple worksheets <g



--
Hope that helps.

Vergel Adriano


"Jim Thomlinson" wrote:

But ws is never selected so the active sheet never changes. Your code will
rename only the active sheet and it will do it multiple times...
--
HTH...

Jim Thomlinson


"Vergel Adriano" wrote:

FatBear,

Your code is looping through all sheets and trying to give all of them the
same name.. try instead:

ActiveSheet.Name = Range("A1").Value


--
Hope that helps.

Vergel Adriano


"FatBear" wrote:

I'm trying to import hockey stats into a spreadsheet.

The first part of the query works great but I want to name the worksheet
based on the player (the name is imported into cell A1).

I'm not sure why this code isn't working. Any help would be appreciated.

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws


The entire query is below for your reference.

Thanks,



Sub Macro1()
' Macro1 Macro
' Macro recorded 4/25/2007 by David White
Dim i As Long
Dim ws As Worksheet
i = 100

Do While i < 110
Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.hockeydb.com/ihdb/stats/pdisplay.php3?pid=" & i,
Destination _
:=Range("A1"))
.Name = "HockeyDB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "5,6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
i = i + 1
Debug.Print Range("A1").Value
Loop

For Each ws In Worksheets
ws.Name = Range("A1").Value
Next ws

End Sub

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Naming worksheets based on a cell value

Thanks everyone for your help.

The code was working but then would throw up an error. I finally realized
that some of the sheets don't have any data so I had to put an if statement
in to delete them.

?B?SmltIFRob21saW5zb24=?=
wrote in
:

Sorry my explanation shoud read "Assuming your code is in..." NOT
"Assuming this code is in..."


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
Naming worksheets tabs from another cell reference Finance Guru Excel Worksheet Functions 2 July 1st 09 07:00 PM
Creating/Naming New Worksheets Based on Select Cells in Master Worksheet Lilbit Excel Worksheet Functions 2 March 19th 08 05:05 PM
naming a file based on cell value? nokia3650 Excel Programming 2 August 3rd 06 07:13 AM
cuting sheet and naming it based on value in specific cell? nokia3650 Excel Programming 0 August 1st 06 02:41 PM
naming .xls file based on a cell in excel lsu-i-like Excel Discussion (Misc queries) 1 June 24th 05 09:44 PM


All times are GMT +1. The time now is 01:11 AM.

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"