#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 74
Default error in code

hi,
could anyone tell me what could possibly be wrong in my code - see remark
below? i keep on getting an error message
thanks

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "QUOTE1"
Const sKEY As String = "QUOTE1_key"
Const nDEFAULT As Long = 1&
Dim nNumber As Long

With ThisWorkbook.Sheets("3") (what could be wrong here?)
With .Range("F9")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With
With .Range("K2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY,
nDEFAULT)
.NumberFormat = "@"
.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End If
End With
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default error in code

hi
what error are you getting????
is the name of the sheet 3 or sheet3?

regards
FSt1

"des-sa" wrote:

hi,
could anyone tell me what could possibly be wrong in my code - see remark
below? i keep on getting an error message
thanks

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "QUOTE1"
Const sKEY As String = "QUOTE1_key"
Const nDEFAULT As Long = 1&
Dim nNumber As Long

With ThisWorkbook.Sheets("3") (what could be wrong here?)
With .Range("F9")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With
With .Range("K2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY,
nDEFAULT)
.NumberFormat = "@"
.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End If
End With
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default error in code

With ThisWorkbook.Sheets("3") (what could be wrong here?)

There is one of two things wrong with that statement (as long as it is the
statement generating your error). When you use quote marks around the
argument, the text between the quote marks has to be the text on the
worksheet's tab. So, if you worksheet is really named Sheet3 (the default
name given it by Excel), then your statement should read....

With ThisWorkbook.Sheets("Sheet3")

On the other hand, if you are actually trying to reference the 3rd tab from
the left's worksheet, then you do not use the quote marks, so your statement
would be this...

With ThisWorkbook.Sheets(3)

One thing to point out with this second version... you users can slide the
tabs around (assuming no protection is in place) so Sheet(3) will be
whatever is currently in the 3rd tab from the left when the statement is
executed (which could theoretically be different than what you are expecting
it to be).

Rick


"des-sa" wrote in message
...
hi,
could anyone tell me what could possibly be wrong in my code - see remark
below? i keep on getting an error message
thanks

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "QUOTE1"
Const sKEY As String = "QUOTE1_key"
Const nDEFAULT As Long = 1&
Dim nNumber As Long

With ThisWorkbook.Sheets("3") (what could be wrong here?)
With .Range("F9")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With
With .Range("K2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY,
nDEFAULT)
.NumberFormat = "@"
.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End If
End With
End With
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 74
Default error in code

hi,
thanks for reply. its says "Run-time error 9 Subscribt out of range

"Rick Rothstein (MVP - VB)" wrote:

With ThisWorkbook.Sheets("3") (what could be wrong here?)


There is one of two things wrong with that statement (as long as it is the
statement generating your error). When you use quote marks around the
argument, the text between the quote marks has to be the text on the
worksheet's tab. So, if you worksheet is really named Sheet3 (the default
name given it by Excel), then your statement should read....

With ThisWorkbook.Sheets("Sheet3")

On the other hand, if you are actually trying to reference the 3rd tab from
the left's worksheet, then you do not use the quote marks, so your statement
would be this...

With ThisWorkbook.Sheets(3)

One thing to point out with this second version... you users can slide the
tabs around (assuming no protection is in place) so Sheet(3) will be
whatever is currently in the 3rd tab from the left when the statement is
executed (which could theoretically be different than what you are expecting
it to be).

Rick


"des-sa" wrote in message
...
hi,
could anyone tell me what could possibly be wrong in my code - see remark
below? i keep on getting an error message
thanks

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "QUOTE1"
Const sKEY As String = "QUOTE1_key"
Const nDEFAULT As Long = 1&
Dim nNumber As Long

With ThisWorkbook.Sheets("3") (what could be wrong here?)
With .Range("F9")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With
With .Range("K2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY,
nDEFAULT)
.NumberFormat = "@"
.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End If
End With
End With
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default error in code

It sounds like your response was meant for FSt1's reply to you, not mine. I
didn't ask you what your error message was because, based on the line you
highlighted in your original post, that is exactly the error message I would
have guessed you had gotten. Did you try changing your code in one of the
ways I outlined to you?

Rick


"des-sa" wrote in message
...
hi,
thanks for reply. its says "Run-time error 9 Subscribt out of range

"Rick Rothstein (MVP - VB)" wrote:

With ThisWorkbook.Sheets("3") (what could be wrong here?)


There is one of two things wrong with that statement (as long as it is
the
statement generating your error). When you use quote marks around the
argument, the text between the quote marks has to be the text on the
worksheet's tab. So, if you worksheet is really named Sheet3 (the default
name given it by Excel), then your statement should read....

With ThisWorkbook.Sheets("Sheet3")

On the other hand, if you are actually trying to reference the 3rd tab
from
the left's worksheet, then you do not use the quote marks, so your
statement
would be this...

With ThisWorkbook.Sheets(3)

One thing to point out with this second version... you users can slide
the
tabs around (assuming no protection is in place) so Sheet(3) will be
whatever is currently in the 3rd tab from the left when the statement is
executed (which could theoretically be different than what you are
expecting
it to be).

Rick


"des-sa" wrote in message
...
hi,
could anyone tell me what could possibly be wrong in my code - see
remark
below? i keep on getting an error message
thanks

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "QUOTE1"
Const sKEY As String = "QUOTE1_key"
Const nDEFAULT As Long = 1&
Dim nNumber As Long

With ThisWorkbook.Sheets("3") (what could be wrong here?)
With .Range("F9")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With
With .Range("K2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY,
nDEFAULT)
.NumberFormat = "@"
.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber +
1&
End If
End With
End With
End Sub






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 74
Default error in code

Rick,
i cant thank you enough, works perfect. thanks again.

i have another question: the template i use is now made up of a few sheets
that i developed on a stand alone work book basis, then copied the sheets
into the template. now when the template opens a message saying my workbook
contains links to other sources do i want to update etc, etc. those links
are now not necessary anymore, but how do i find them to destroy them
thanks again
disri

"Rick Rothstein (MVP - VB)" wrote:

It sounds like your response was meant for FSt1's reply to you, not mine. I
didn't ask you what your error message was because, based on the line you
highlighted in your original post, that is exactly the error message I would
have guessed you had gotten. Did you try changing your code in one of the
ways I outlined to you?

Rick


"des-sa" wrote in message
...
hi,
thanks for reply. its says "Run-time error 9 Subscribt out of range

"Rick Rothstein (MVP - VB)" wrote:

With ThisWorkbook.Sheets("3") (what could be wrong here?)

There is one of two things wrong with that statement (as long as it is
the
statement generating your error). When you use quote marks around the
argument, the text between the quote marks has to be the text on the
worksheet's tab. So, if you worksheet is really named Sheet3 (the default
name given it by Excel), then your statement should read....

With ThisWorkbook.Sheets("Sheet3")

On the other hand, if you are actually trying to reference the 3rd tab
from
the left's worksheet, then you do not use the quote marks, so your
statement
would be this...

With ThisWorkbook.Sheets(3)

One thing to point out with this second version... you users can slide
the
tabs around (assuming no protection is in place) so Sheet(3) will be
whatever is currently in the 3rd tab from the left when the statement is
executed (which could theoretically be different than what you are
expecting
it to be).

Rick


"des-sa" wrote in message
...
hi,
could anyone tell me what could possibly be wrong in my code - see
remark
below? i keep on getting an error message
thanks

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "QUOTE1"
Const sKEY As String = "QUOTE1_key"
Const nDEFAULT As Long = 1&
Dim nNumber As Long

With ThisWorkbook.Sheets("3") (what could be wrong here?)
With .Range("F9")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With
With .Range("K2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY,
nDEFAULT)
.NumberFormat = "@"
.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber +
1&
End If
End With
End With
End Sub




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
Code error M&M[_2_] Excel Discussion (Misc queries) 4 July 13th 07 12:20 AM
Code error N.F[_2_] Excel Discussion (Misc queries) 1 July 2nd 07 11:13 PM
Error in Code N.F[_2_] Excel Discussion (Misc queries) 9 June 27th 07 06:48 PM
error in this code [email protected] Excel Worksheet Functions 2 December 5th 06 05:21 AM
Error Code 481 MBlake Excel Discussion (Misc queries) 1 May 11th 05 01:27 PM


All times are GMT +1. The time now is 04:02 AM.

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"