Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using variable to call worksheets


I am writing a program that takes information a user enters (string) and
uses it to create a sheet with that name. So far it has been extremely
unreliable, working one minute and then not the next. The variable is
marked as a string, so it "shouldn't" be looking for the worksheet by
number. Oh, the information in the variable is a number. Ok, so it
looks for the worksheet by name using the variable. If it can't find
it, the error causes it to create a new worksheet with that name. But,
the darn program keeps making "SheetX" with X representing the next
sheet number (1,2,3,4,5 etc). It has actually worked a couple of times,
but apparently is unstable. The variable is a public string since it is
used in two or three routines. Would making it a private variable and
passing it just between these routines help? My other worksheet
function that activates a worksheet and unhides it works just fine
using a private string.
Craig Robson


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Using variable to call worksheets

Craig,

Post the code.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Calypsoblur" wrote in message
...

I am writing a program that takes information a user enters (string) and
uses it to create a sheet with that name. So far it has been extremely
unreliable, working one minute and then not the next. The variable is
marked as a string, so it "shouldn't" be looking for the worksheet by
number. Oh, the information in the variable is a number. Ok, so it
looks for the worksheet by name using the variable. If it can't find
it, the error causes it to create a new worksheet with that name. But,
the darn program keeps making "SheetX" with X representing the next
sheet number (1,2,3,4,5 etc). It has actually worked a couple of times,
but apparently is unstable. The variable is a public string since it is
used in two or three routines. Would making it a private variable and
passing it just between these routines help? My other worksheet
function that activates a worksheet and unhides it works just fine
using a private string.
Craig Robson


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using variable to call worksheets


PumpNumber is the Public string variable. The purpose of the routine is
just to activate the sheet so that I can enter information about the
pump into it.



'Checks for sheet PumpSheet and creates it if it does
'not exist.

Public Sub NewSheet()

'If error is created then continues
On Error Resume Next

'Tries to activate the sheet PumpSheet
Sheets(PumpNumber).Activate

'Creates the sheet PumpSheet
If Err < 0 Then
Sheets.Add
ActiveSheets.Name = PumpNumber
'Enters header information
Range("A1") = "Number"
Range("B1") = "Hours"
Range("C1") = "Date"
Range("D1") = "Lugs"

End If

'Restores normal error handling
On Error GoTo 0

End Sub


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Using variable to call worksheets

Try it like this:

'PumpNumber is the Public string variable. The purpose of the routine is
'just to activate the sheet so that I can enter information about the
'pump into it.

Dim PumpNumber As Long

Sub test()
For i = 5 To 10
PumpNumber = i
NewSheet
Next 'i
End Sub

'Checks for sheet PumpSheet and creates it if it does
'not exist.

Public Sub NewSheet()

'If error is created then continues
On Error Resume Next

'Tries to activate the sheet PumpSheet
Sheets(PumpNumber).Activate

'Creates the sheet PumpSheet
If Err < 0 Then
Set xSheet = Worksheets.Add(after:=Worksheets(Worksheets.Count) )
With xSheet
.Name = PumpNumber
'Enters header information
.Range("A1") = "Number"
.Range("B1") = "Hours"
.Range("C1") = "Date"
.Range("D1") = "Lugs"
End With

End If

'Restores normal error handling
On Error GoTo 0

End Sub

Regards

Trevor


"Calypsoblur" wrote in message
...

PumpNumber is the Public string variable. The purpose of the routine is
just to activate the sheet so that I can enter information about the
pump into it.



'Checks for sheet PumpSheet and creates it if it does
'not exist.

Public Sub NewSheet()

'If error is created then continues
On Error Resume Next

'Tries to activate the sheet PumpSheet
Sheets(PumpNumber).Activate

'Creates the sheet PumpSheet
If Err < 0 Then
Sheets.Add
ActiveSheets.Name = PumpNumber
'Enters header information
Range("A1") = "Number"
Range("B1") = "Hours"
Range("C1") = "Date"
Range("D1") = "Lugs"

End If

'Restores normal error handling
On Error GoTo 0

End Sub


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



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 a Call to an external sheet using a variable... [email protected] Excel Worksheet Functions 2 January 19th 07 03:19 PM
Call Center Management: How to calculate 'cost per call' Denniso6 Excel Discussion (Misc queries) 2 June 25th 06 05:01 PM
How to keep a Variable alive after a Call to Sub Routine Dennis Excel Discussion (Misc queries) 2 July 27th 05 10:57 PM
Can I use a variable to call up another sheet in Excel? GD Cooley Excel Worksheet Functions 1 February 13th 05 05:40 AM
Can I use a variable to call up another sheet in Excel? GD Cooley Excel Worksheet Functions 0 February 11th 05 02:47 PM


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