Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Help in VBA.

Dear all experts,
I am totally new to VBA. I have make use of a set of code provided by Mr.
Paul Sheppard. But I am encountering errors.

What I want to do is:
To update the 13 worksheet's name referencing to another file called Staff
Names for timesheet.xls, worksheet name called "IT" and from cell b2 ~ B14
This Staff Names for timesheet.xls path is C:\Document folder\Timesheet


Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for
timesheet.xls").Worksheet("IT").Range("b2:b14").Va lue
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

This is definitely a simple questions to the experts out there, appreciate
very much.
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help in VBA.

Maybe...

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for timesheet.xls") _
.Worksheet("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i
End Sub

If this doesn't help, maybe you can explain what's going wrong.

YY san. wrote:

Dear all experts,
I am totally new to VBA. I have make use of a set of code provided by Mr.
Paul Sheppard. But I am encountering errors.

What I want to do is:
To update the 13 worksheet's name referencing to another file called Staff
Names for timesheet.xls, worksheet name called "IT" and from cell b2 ~ B14
This Staff Names for timesheet.xls path is C:\Document folder\Timesheet

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for
timesheet.xls").Worksheet("IT").Range("b2:b14").Va lue
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

This is definitely a simple questions to the experts out there, appreciate
very much.
Thanks!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Help in VBA.

Thanks Dave! It works(except "Worksheet" encoutered an error. But it is OK
after I have it changed to "Worksheet").
Another question: What is the syntax if I want to specify the path where
this "Staff Names for timesheet.xls" is located? I realised that if I dont
open this file at the same time, it will not work.
Thanks again.

"Dave Peterson" wrote:

Maybe...

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for timesheet.xls") _
.Worksheet("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i
End Sub

If this doesn't help, maybe you can explain what's going wrong.

YY san. wrote:

Dear all experts,
I am totally new to VBA. I have make use of a set of code provided by Mr.
Paul Sheppard. But I am encountering errors.

What I want to do is:
To update the 13 worksheet's name referencing to another file called Staff
Names for timesheet.xls, worksheet name called "IT" and from cell b2 ~ B14
This Staff Names for timesheet.xls path is C:\Document folder\Timesheet

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for
timesheet.xls").Worksheet("IT").Range("b2:b14").Va lue
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

This is definitely a simple questions to the experts out there, appreciate
very much.
Thanks!


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help in VBA.

I didn't notice that typo in the original post. Glad you caught it.

But you don't specify the path in the workbooks() collection. The workbook has
to be open before you can use your code. But you could open it in your macro:

Sub namesheets()
dim TSWkbk as workbook
Dim arr As Variant

set tswkbk = nothing
on error resume next
set tswkbk = workbooks("staff names for timesheet.xls")
on error goto 0

if tswkbk is nothing then
set tswkbk _
= workbooks.open(filename:="C:\yourpath\Staff Names for timesheet.xls")
end if

arr = tswkbk.Worksheets("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i

End Sub

YY san. wrote:

Thanks Dave! It works(except "Worksheet" encoutered an error. But it is OK
after I have it changed to "Worksheet").
Another question: What is the syntax if I want to specify the path where
this "Staff Names for timesheet.xls" is located? I realised that if I dont
open this file at the same time, it will not work.
Thanks again.

"Dave Peterson" wrote:

Maybe...

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for timesheet.xls") _
.Worksheet("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i
End Sub

If this doesn't help, maybe you can explain what's going wrong.

YY san. wrote:

Dear all experts,
I am totally new to VBA. I have make use of a set of code provided by Mr.
Paul Sheppard. But I am encountering errors.

What I want to do is:
To update the 13 worksheet's name referencing to another file called Staff
Names for timesheet.xls, worksheet name called "IT" and from cell b2 ~ B14
This Staff Names for timesheet.xls path is C:\Document folder\Timesheet

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for
timesheet.xls").Worksheet("IT").Range("b2:b14").Va lue
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

This is definitely a simple questions to the experts out there, appreciate
very much.
Thanks!


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Help in VBA.

Thanks Dave. It works perfect!!
However, I have another simple question:
If I want the macro to update the worksheet name from Sheet2(skip Sheet1).
How can I code this?
regards,

"Dave Peterson" wrote:

I didn't notice that typo in the original post. Glad you caught it.

But you don't specify the path in the workbooks() collection. The workbook has
to be open before you can use your code. But you could open it in your macro:

Sub namesheets()
dim TSWkbk as workbook
Dim arr As Variant

set tswkbk = nothing
on error resume next
set tswkbk = workbooks("staff names for timesheet.xls")
on error goto 0

if tswkbk is nothing then
set tswkbk _
= workbooks.open(filename:="C:\yourpath\Staff Names for timesheet.xls")
end if

arr = tswkbk.Worksheets("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i

End Sub

YY san. wrote:

Thanks Dave! It works(except "Worksheet" encoutered an error. But it is OK
after I have it changed to "Worksheet").
Another question: What is the syntax if I want to specify the path where
this "Staff Names for timesheet.xls" is located? I realised that if I dont
open this file at the same time, it will not work.
Thanks again.

"Dave Peterson" wrote:

Maybe...

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for timesheet.xls") _
.Worksheet("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i
End Sub

If this doesn't help, maybe you can explain what's going wrong.

YY san. wrote:

Dear all experts,
I am totally new to VBA. I have make use of a set of code provided by Mr.
Paul Sheppard. But I am encountering errors.

What I want to do is:
To update the 13 worksheet's name referencing to another file called Staff
Names for timesheet.xls, worksheet name called "IT" and from cell b2 ~ B14
This Staff Names for timesheet.xls path is C:\Document folder\Timesheet

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for
timesheet.xls").Worksheet("IT").Range("b2:b14").Va lue
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

This is definitely a simple questions to the experts out there, appreciate
very much.
Thanks!

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help in VBA.

Maybe...

For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i+1).Name = arr(i, 1)
Next i



YY san. wrote:

Thanks Dave. It works perfect!!
However, I have another simple question:
If I want the macro to update the worksheet name from Sheet2(skip Sheet1).
How can I code this?
regards,

"Dave Peterson" wrote:

I didn't notice that typo in the original post. Glad you caught it.

But you don't specify the path in the workbooks() collection. The workbook has
to be open before you can use your code. But you could open it in your macro:

Sub namesheets()
dim TSWkbk as workbook
Dim arr As Variant

set tswkbk = nothing
on error resume next
set tswkbk = workbooks("staff names for timesheet.xls")
on error goto 0

if tswkbk is nothing then
set tswkbk _
= workbooks.open(filename:="C:\yourpath\Staff Names for timesheet.xls")
end if

arr = tswkbk.Worksheets("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i

End Sub

YY san. wrote:

Thanks Dave! It works(except "Worksheet" encoutered an error. But it is OK
after I have it changed to "Worksheet").
Another question: What is the syntax if I want to specify the path where
this "Staff Names for timesheet.xls" is located? I realised that if I dont
open this file at the same time, it will not work.
Thanks again.

"Dave Peterson" wrote:

Maybe...

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for timesheet.xls") _
.Worksheet("IT").Range("b2:b14").Value
For i = LBound(arr, 1) To UBound(arr, 1)
Sheets(i).Name = arr(i, 1)
Next i
End Sub

If this doesn't help, maybe you can explain what's going wrong.

YY san. wrote:

Dear all experts,
I am totally new to VBA. I have make use of a set of code provided by Mr.
Paul Sheppard. But I am encountering errors.

What I want to do is:
To update the 13 worksheet's name referencing to another file called Staff
Names for timesheet.xls, worksheet name called "IT" and from cell b2 ~ B14
This Staff Names for timesheet.xls path is C:\Document folder\Timesheet

Sub namesheets()
Dim arr As Variant
arr = Workbooks("Staff Names for
timesheet.xls").Worksheet("IT").Range("b2:b14").Va lue
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

This is definitely a simple questions to the experts out there, appreciate
very much.
Thanks!

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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



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