Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 361
Default Macro Modification

I am using this macro:

Option Explicit
Sub maketable2()
Dim SheetList As Sheets
Dim RngToName As Range
Dim LastRow As Long
Dim LastCol As Long
Dim NameToUse As String
Dim sh As Worksheet

Set SheetList = ActiveWindow.SelectedSheets
For Each sh In SheetList
NameToUse = Application.InputBox(Prompt:="Enter the Table Name")
If Trim(NameToUse) = "" Then
Exit Sub 'what should happen here
End If
With sh
LastRow = .Range("a10").End(xlDown).Row
LastCol = .Range("a10").End(xlToRight).Column
Set RngToName = .Range("a10", .Cells(LastRow, LastCol))
'.Names.Add Name:="'" & .Name & "'!" & NameToUse, _
RefersTo:=RngToName, Visible:=True
'or global name??
RngToName.Name = NameToUse
End With
Next sh
End Sub


The macro helps me create lookup tables. Is it possible to have the Macro
name the tables based on a list like this:

Aug1
Aug2
Aug3
Aug4
Aug5
Aug6
Aug7
Aug8

Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Macro Modification

Asuming that the list is named SheetNames, then

Sub maketable2()
Dim SheetList As Sheets
Dim RngToName As Range
Dim LastRow As Long
Dim LastCol As Long
Dim NameToUse As String
Dim sh As Worksheet
Dim i As Long

Set SheetList = ActiveWindow.SelectedSheets
For Each sh In SheetList
i = i + 1
If Application.Range("SheetNames").Cells(i, 1).Value < "" Then
With sh
LastRow = .Range("a10").End(xlDown).Row
LastCol = .Range("a10").End(xlToRight).Column
Set RngToName = .Range("a10", .Cells(LastRow, LastCol))
RngToName.Name = Application.Range("SheetNames").Cells(i,
1).Value
End With
End If
Next sh
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"carl" wrote in message
...
I am using this macro:

Option Explicit
Sub maketable2()
Dim SheetList As Sheets
Dim RngToName As Range
Dim LastRow As Long
Dim LastCol As Long
Dim NameToUse As String
Dim sh As Worksheet

Set SheetList = ActiveWindow.SelectedSheets
For Each sh In SheetList
NameToUse = Application.InputBox(Prompt:="Enter the Table Name")
If Trim(NameToUse) = "" Then
Exit Sub 'what should happen here
End If
With sh
LastRow = .Range("a10").End(xlDown).Row
LastCol = .Range("a10").End(xlToRight).Column
Set RngToName = .Range("a10", .Cells(LastRow, LastCol))
'.Names.Add Name:="'" & .Name & "'!" & NameToUse, _
RefersTo:=RngToName, Visible:=True
'or global name??
RngToName.Name = NameToUse
End With
Next sh
End Sub


The macro helps me create lookup tables. Is it possible to have the Macro
name the tables based on a list like this:

Aug1
Aug2
Aug3
Aug4
Aug5
Aug6
Aug7
Aug8

Thank you in advance.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 361
Default Macro Modification

Thank You Bob. You have been so helpful now and in the past. Thanks Again.

"Bob Phillips" wrote:

Asuming that the list is named SheetNames, then

Sub maketable2()
Dim SheetList As Sheets
Dim RngToName As Range
Dim LastRow As Long
Dim LastCol As Long
Dim NameToUse As String
Dim sh As Worksheet
Dim i As Long

Set SheetList = ActiveWindow.SelectedSheets
For Each sh In SheetList
i = i + 1
If Application.Range("SheetNames").Cells(i, 1).Value < "" Then
With sh
LastRow = .Range("a10").End(xlDown).Row
LastCol = .Range("a10").End(xlToRight).Column
Set RngToName = .Range("a10", .Cells(LastRow, LastCol))
RngToName.Name = Application.Range("SheetNames").Cells(i,
1).Value
End With
End If
Next sh
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"carl" wrote in message
...
I am using this macro:

Option Explicit
Sub maketable2()
Dim SheetList As Sheets
Dim RngToName As Range
Dim LastRow As Long
Dim LastCol As Long
Dim NameToUse As String
Dim sh As Worksheet

Set SheetList = ActiveWindow.SelectedSheets
For Each sh In SheetList
NameToUse = Application.InputBox(Prompt:="Enter the Table Name")
If Trim(NameToUse) = "" Then
Exit Sub 'what should happen here
End If
With sh
LastRow = .Range("a10").End(xlDown).Row
LastCol = .Range("a10").End(xlToRight).Column
Set RngToName = .Range("a10", .Cells(LastRow, LastCol))
'.Names.Add Name:="'" & .Name & "'!" & NameToUse, _
RefersTo:=RngToName, Visible:=True
'or global name??
RngToName.Name = NameToUse
End With
Next sh
End Sub


The macro helps me create lookup tables. Is it possible to have the Macro
name the tables based on a list like this:

Aug1
Aug2
Aug3
Aug4
Aug5
Aug6
Aug7
Aug8

Thank you in advance.




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
how do I email amacro? leo Excel Worksheet Functions 24 August 9th 06 02:47 PM
link to combobox legepe Excel Discussion (Misc queries) 4 July 26th 06 04:45 PM
Editing a simple macro Connie Martin Excel Worksheet Functions 5 November 29th 05 09:19 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Macro Modification Help Dmorri254 Excel Worksheet Functions 0 March 4th 05 03:51 PM


All times are GMT +1. The time now is 09:37 AM.

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"