Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Adding a new Sheet but not making it the Active Sheet

Hi

I want to add a new sheet to a workbook but not make it the active
sheet, is that possible?

I've written some code that loops through a worksheet, that is
referred to as the active sheet and then outputs the results onto
another, new sheet in the same workbook. I want to refer to the new
sheet by it's name and keep the active sheet as the active sheet.

Failing that how do you make a sheet active or not?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Adding a new Sheet but not making it the Active Sheet

There is another way I can't remember right now but try this.

Sub addshtwoactive()
goback = ActiveSheet.Name
MsgBox goback
Sheets.Add
Sheets(goback).Select
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"David" wrote in message
ups.com...
Hi

I want to add a new sheet to a workbook but not make it the active
sheet, is that possible?

I've written some code that loops through a worksheet, that is
referred to as the active sheet and then outputs the results onto
another, new sheet in the same workbook. I want to refer to the new
sheet by it's name and keep the active sheet as the active sheet.

Failing that how do you make a sheet active or not?

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Adding a new Sheet but not making it the Active Sheet

You could just keep track

Dim ActWks as worksheet
dim NewWks as worksheet

set ActWks = activesheet
set newwks = worksheets.add
'go back to the sheet that was active
Actwks.select

But instead of refering to the new worksheet by its name, you could use the
newwks variable:

newwks.range("a1").value = "hi"
newwks.name = "newsheetnamehere"



David wrote:

Hi

I want to add a new sheet to a workbook but not make it the active
sheet, is that possible?

I've written some code that loops through a worksheet, that is
referred to as the active sheet and then outputs the results onto
another, new sheet in the same workbook. I want to refer to the new
sheet by it's name and keep the active sheet as the active sheet.

Failing that how do you make a sheet active or not?

Thanks.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Adding a new Sheet but not making it the Active Sheet

On Oct 16, 3:02 pm, Dave Peterson wrote:
You could just keep track

Dim ActWks as worksheet
dim NewWks as worksheet

set ActWks = activesheet
set newwks = worksheets.add
'go back to the sheet that was active
Actwks.select

But instead of refering to the new worksheet by its name, you could use the
newwks variable:

newwks.range("a1").value = "hi"
newwks.name = "newsheetnamehere"

David wrote:

Hi


I want to add a new sheet to a workbook but not make it the active
sheet, is that possible?


I've written some code that loops through a worksheet, that is
referred to as the active sheet and then outputs the results onto
another, new sheet in the same workbook. I want to refer to the new
sheet by it's name and keep the active sheet as the active sheet.


Failing that how do you make a sheet active or not?


Thanks.


--

Dave Peterson


Thanks but I either didn't explain properly or did something wrong as
it isn't working for me.

I added this to all functions:

Dim Sheet1 As Worksheet
Dim Sheet4 As Worksheet

I then added this to the function that opens the new file for
processing:

Set Sheet1 = ActiveSheet
Set Sheet4 = Worksheets.Add

'go back to the sheet that was active
Sheet1.Select

That all seems to be OK.

Then, I added this where the output needs to be processed:

Set Sheet4 = ActiveSheet

Sheet4.Select

Sheet4.Cells(1, 1).Value = "Results"

This is being output onto Sheet1, if I put
ActiveSheet.Cells(1,1).Value = "Results" it still puts it onto Sheet1.

What am I doing wrong? I'm using Excel '97 if that's the problem.

I could use an array to store the output in and then once everything
has been processed output it at the end but that would be quite slow I
suspect as there is a lot of data to be processed.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Adding a new Sheet but not making it the Active Sheet

First, those variable names are (probably) the same as what excel used for your
code names.

So try replacing this:

Dim Sheet1 As Worksheet
Dim Sheet4 As Worksheet
with
Dim mySheet1 As Worksheet
Dim mySheet4 As Worksheet

But I don't think your code will work:

Set mySheet1 = ActiveSheet
Set mySheet4 = Worksheets.Add

mySheet1.Select

'this line will now have mySheet4 point to whatever sheet was active
'in this case, it points at the same sheet as mySheet1--the currently
'activesheet
Set mySheet4 = ActiveSheet

'this stays on the activesheet
mySheet4.Select

Sheet4.Cells(1, 1).Value = "Results"

============
I'd still use variable names that were a little more descriptive.

Dim ActWks as worksheet
dim NewWks as worksheet
set ActWks = activesheet
set newwks = worksheets.add
'go back to the sheet that was active
Actwks.select
'put something in the new worksheet
newwks.range("a1").value = "Results"



David wrote:

On Oct 16, 3:02 pm, Dave Peterson wrote:
You could just keep track

Dim ActWks as worksheet
dim NewWks as worksheet

set ActWks = activesheet
set newwks = worksheets.add
'go back to the sheet that was active
Actwks.select

But instead of refering to the new worksheet by its name, you could use the
newwks variable:

newwks.range("a1").value = "hi"
newwks.name = "newsheetnamehere"

David wrote:

Hi


I want to add a new sheet to a workbook but not make it the active
sheet, is that possible?


I've written some code that loops through a worksheet, that is
referred to as the active sheet and then outputs the results onto
another, new sheet in the same workbook. I want to refer to the new
sheet by it's name and keep the active sheet as the active sheet.


Failing that how do you make a sheet active or not?


Thanks.


--

Dave Peterson


Thanks but I either didn't explain properly or did something wrong as
it isn't working for me.

I added this to all functions:

Dim Sheet1 As Worksheet
Dim Sheet4 As Worksheet

I then added this to the function that opens the new file for
processing:

Set Sheet1 = ActiveSheet
Set Sheet4 = Worksheets.Add

'go back to the sheet that was active
Sheet1.Select

That all seems to be OK.

Then, I added this where the output needs to be processed:

Set Sheet4 = ActiveSheet

Sheet4.Select

Sheet4.Cells(1, 1).Value = "Results"

This is being output onto Sheet1, if I put
ActiveSheet.Cells(1,1).Value = "Results" it still puts it onto Sheet1.

What am I doing wrong? I'm using Excel '97 if that's the problem.

I could use an array to store the output in and then once everything
has been processed output it at the end but that would be quite slow I
suspect as there is a lot of data to be processed.


--

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making for adding and naming a new sheet michaelberrier Excel Discussion (Misc queries) 13 May 29th 06 07:58 PM
Active Cell Copy And Paste Sheet to Sheet A.R.J Allan Jefferys New Users to Excel 4 May 4th 06 02:04 AM
Copy my active sheet to a new sheet and open with an input form Brad Withrow Excel Programming 0 April 6th 06 03:56 AM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Excel Programming 3 January 23rd 06 09:57 PM
Adding Items To Active X ComboBox on Sheet Dan Gesshel Excel Programming 3 October 20th 03 01:02 PM


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