Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Adding a sheets name to the worksheets that are copied over from an addin file to the activeworkbook

Hi
I'm using the following code to copy 2 worksheets from and addin file and
insert them into the activeworkbook.
The With part of the code changes cells A1, A2 and A3 from text to formulas
(as I was having problems with ranges etc...)
Anyway.. it works great...
but now I want to add the "sheet name" to cell A4 of the two sheets that get
copied over (Summary Pay I and Pay I Details.)
When they are copied over to the activeworkbook, their name changes to
Summary Pay I (2) , Pay I Details (2)
and so on as more are added.
I'm not sure how to do this...???

Public Sub AddPayIWS()
'Add more sheets to audit
Application.ScreenUpdating = False
PayIStateLoc.Show
Workbooks("TESTAddin.xla").Sheets(Array("Summary Pay I", "Pay I
Details")).Copy After:=ActiveWorkbook.Worksheets(Worksheets.Count)
MsgBox "New Pay I Worksheets have been added!"
With ActiveWorkbook
For i = .Worksheets.Count To .Worksheets.Count - 1 Step -1
With Worksheets(i)
.Range("A1").Formula = .Range("A1").Value
.Range("A2").Formula = .Range("A2").Value
.Range("A3").Formula = .Range("A3").Value
.Protect Password:="Test", DrawingObjects:=True, Contents:=True,
Scenarios:=True

End With
Next
End With
Application.ScreenUpdating = True
End Sub



Thanks in advance!
Kimberly


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Adding a sheets name to the worksheets that are copied over from a

For i = .Worksheets.Count To .Worksheets.Count - 1 Step -1
With Worksheets(i)
.Range("A1").Formula = .Range("A1").Value
.Range("A2").Formula = .Range("A2").Value
.Range("A3").Formula = .Range("A3").Value
'Add sheet name
.Range("A4").Value = .Name
.Protect Password:="Test", DrawingObjects:=True, Contents:=True,
Scenarios:=True

or to get rid of the Space(2)
use
.Range("A4").Value = left(.Name, Len(.Name)-4)

End With
Next


"KimberlyC" wrote:

Hi
I'm using the following code to copy 2 worksheets from and addin file and
insert them into the activeworkbook.
The With part of the code changes cells A1, A2 and A3 from text to formulas
(as I was having problems with ranges etc...)
Anyway.. it works great...
but now I want to add the "sheet name" to cell A4 of the two sheets that get
copied over (Summary Pay I and Pay I Details.)
When they are copied over to the activeworkbook, their name changes to
Summary Pay I (2) , Pay I Details (2)
and so on as more are added.
I'm not sure how to do this...???

Public Sub AddPayIWS()
'Add more sheets to audit
Application.ScreenUpdating = False
PayIStateLoc.Show
Workbooks("TESTAddin.xla").Sheets(Array("Summary Pay I", "Pay I
Details")).Copy After:=ActiveWorkbook.Worksheets(Worksheets.Count)
MsgBox "New Pay I Worksheets have been added!"
With ActiveWorkbook
For i = .Worksheets.Count To .Worksheets.Count - 1 Step -1
With Worksheets(i)
.Range("A1").Formula = .Range("A1").Value
.Range("A2").Formula = .Range("A2").Value
.Range("A3").Formula = .Range("A3").Value
.Protect Password:="Test", DrawingObjects:=True, Contents:=True,
Scenarios:=True

End With
Next
End With
Application.ScreenUpdating = True
End Sub



Thanks in advance!
Kimberly



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Adding a sheets name to the worksheets that are copied over from a

Thank you!!! :)
It Works great!!
"cush" wrote in message
...
For i = .Worksheets.Count To .Worksheets.Count - 1 Step -1
With Worksheets(i)
.Range("A1").Formula = .Range("A1").Value
.Range("A2").Formula = .Range("A2").Value
.Range("A3").Formula = .Range("A3").Value
'Add sheet name
.Range("A4").Value = .Name
.Protect Password:="Test", DrawingObjects:=True, Contents:=True,
Scenarios:=True

or to get rid of the Space(2)
use
.Range("A4").Value = left(.Name, Len(.Name)-4)

End With
Next


"KimberlyC" wrote:

Hi
I'm using the following code to copy 2 worksheets from and addin file

and
insert them into the activeworkbook.
The With part of the code changes cells A1, A2 and A3 from text to

formulas
(as I was having problems with ranges etc...)
Anyway.. it works great...
but now I want to add the "sheet name" to cell A4 of the two sheets that

get
copied over (Summary Pay I and Pay I Details.)
When they are copied over to the activeworkbook, their name changes to
Summary Pay I (2) , Pay I Details (2)
and so on as more are added.
I'm not sure how to do this...???

Public Sub AddPayIWS()
'Add more sheets to audit
Application.ScreenUpdating = False
PayIStateLoc.Show
Workbooks("TESTAddin.xla").Sheets(Array("Summary Pay I", "Pay I
Details")).Copy After:=ActiveWorkbook.Worksheets(Worksheets.Count)
MsgBox "New Pay I Worksheets have been added!"
With ActiveWorkbook
For i = .Worksheets.Count To .Worksheets.Count - 1 Step -1
With Worksheets(i)
.Range("A1").Formula = .Range("A1").Value
.Range("A2").Formula = .Range("A2").Value
.Range("A3").Formula = .Range("A3").Value
.Protect Password:="Test", DrawingObjects:=True, Contents:=True,
Scenarios:=True

End With
Next
End With
Application.ScreenUpdating = True
End Sub



Thanks in advance!
Kimberly





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
File placement with copied sheets AE Excel Worksheet Functions 1 May 31st 10 03:04 PM
How do i assign the ActiveWorkbook.Worksheets to a worksheets object? TS Excel Worksheet Functions 2 December 27th 06 02:49 PM
Excel file 4MB.Copied sheets to a new file.Now=64Kb-easier way? Suza Excel Discussion (Misc queries) 2 March 27th 06 03:15 PM
ActiveWorkbook.Sheets.Count yankee428 Excel Programming 5 November 10th 04 06:22 AM
Question about accessing worksheets on an AddIn file 39N95W Excel Programming 1 May 25th 04 03:11 AM


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