473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Accessing newly created worksheet in Excel

Hi all,
I've created a workbook to play a game with my friends. Each time I insert
results a new worksheet should be created (which happens) and then this
worksheet should be activated. I'm fairly new to VBA but have used object
oriented programming before.
The following code I created with the help of the build-in help file.
' werkblad voor uitslag per race maken
ActiveWorkbook.Sheets.Add _
after:=Worksheets(Worksheets.Count)
iWerkbladen = Sheets.Count
Worksheets("Sheet" & iWerkbladen).Activate // this line is
listed as 'the problem'
ActiveSheet.Name = sRace
Range("A1").Text = "Deelnemer"
Range("B1").Text = "Punten"

The error message I get is: subscript out of range
Can any of you please tell me what I'm doing wrong and how to do it
correctly?
T.i.a.
--
Punky

Leven is leven dat leven wil te midden van leven dat leven wil (dr. A.
Schweitzer)

Jul 17 '05 #1
3 11377
See inline below...

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"Punky" <li*********@wanadoo.nl> wrote in message
news:42***********************@news.wanadoo.nl...
Hi all,
I've created a workbook to play a game with my friends. Each time I insert
results a new worksheet should be created (which happens) and then this
worksheet should be activated. I'm fairly new to VBA but have used object
oriented programming before.
The following code I created with the help of the build-in help file.
' werkblad voor uitslag per race maken
ActiveWorkbook.Sheets.Add _
after:=Worksheets(Worksheets.Count)
iWerkbladen = Sheets.Count
ActiveWorkbook.Sheets(.Sheets(Worksheets.Count+ 1).Name).Select
ActiveSheet.Name = sRace
Range("A1").Text = "Deelnemer"
Range("B1").Text = "Punten"

The error message I get is: subscript out of range
Can any of you please tell me what I'm doing wrong and how to do it
correctly?
T.i.a.
--
Punky

Leven is leven dat leven wil te midden van leven dat leven wil (dr. A.
Schweitzer)

Jul 17 '05 #2

"Veign" <me@home.com> schreef in bericht
news:UC****************@newsread2.news.atl.earthli nk.net...
See inline below...

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"Punky" <li*********@wanadoo.nl> wrote in message
news:42***********************@news.wanadoo.nl...
Hi all,
I've created a workbook to play a game with my friends. Each time I insert results a new worksheet should be created (which happens) and then this
worksheet should be activated. I'm fairly new to VBA but have used object oriented programming before.
The following code I created with the help of the build-in help file.
' werkblad voor uitslag per race maken
ActiveWorkbook.Sheets.Add _
after:=Worksheets(Worksheets.Count)
iWerkbladen = Sheets.Count
ActiveWorkbook.Sheets(.Sheets(Worksheets.Count+

1).Name).Select
ActiveSheet.Name = sRace
Range("A1").Text = "Deelnemer"
Range("B1").Text = "Punten"

The error message I get is: subscript out of range
Can any of you please tell me what I'm doing wrong and how to do it
correctly?
T.i.a.
--
Punky

Leven is leven dat leven wil te midden van leven dat leven wil (dr. A.
Schweitzer)

Found out that when you create a new worksheet, it automatically gets focus,
so you don't need to activate it. So that's that problem solved.

Now out of the blue things that worked fine last year start creating errors
in the new app, when all I changed was the name of the app, which doesn't
appear anywhere in the code.
In the above code the lines Range ("A1").Text = "Deelnemer" and the one
below won't do what I expect them to and the lines I use (and have
successfully used last year) for writing data to cells give an error 424:
object requiered (or similar, language is Dutch (object vereist)). This is
the code I use:
If Range("M3").Text = sRace Then
ActiveCell.Offset(0, 12).Value = iPunten
It has to step through a number of cells to find the match and then write
the value to the appropriate cell.
I hope someone can help me.
--
Punky

Leven is leven dat leven wil te midden van leven dat leven wil (dr. A.
Schweitzer)
Jul 17 '05 #3

"Punky" <li*********@wanadoo.nl> wrote in message
news:42***********************@news.wanadoo.nl...

| In the above code the lines Range ("A1").Text = "Deelnemer" and the
one
| below won't do what I expect them to and the lines I use (and have
| successfully used last year) for writing data to cells give an error
424:
| object requiered (or similar, language is Dutch (object vereist)).
This is
| the code I use:
| If Range("M3").Text = sRace Then
| ActiveCell.Offset(0, 12).Value = iPunten

In my Excel 97 help file, the Text property is listed as Read Only for
the range object.
I think using the Value property instead should work:

Range("A1").Value = "Deelnemer"

I'm not sure about the second one. However ActiveCell may not refer to
Range("M3"), if that is what you want. Maybe what you need is

Range("M3").Offset(0,12).Value = iPunten
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
2
by: Anne Sachleben via AccessMonster.com | last post by:
I am using the TransferSpreadsheet function to export a query result to a specific worksheet in an Excel file titled "report". I want the result to be exported to the worksheet titled "facts". ...
2
by: Kumar | last post by:
Hi Folks, I have a question regarding my windows c# application. This application just reads MS Excel file and puts the data in to sql server database. In that excel file ,it has one named cell...
1
by: sk | last post by:
Please forgive me if the same topic is already posted. But i havent found I have got an error while accessing the excel file as below. Can somebody reply if there is a solution Access is denied....
0
by: vinidimple | last post by:
Hi i have a serious problem while i was working in Excel.I want to fetch columns from an excel worksheet and i need to compare it with an sql querry fields,so i tried to open an excle...
0
by: sradoff | last post by:
I wish to use XPath to access data from within an Excel generated XML Spreadsheet (generated with MS Excel 2003). I am using an asp Web page (not .NET, not at this time). I instantiate...
0
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a problem. After lots of combinations, I finally...
2
by: Steve Kershaw | last post by:
Hello, I've been trying to spin off an Excel worksheet on the client from an ASP.NET website. I was successfull in displaying an Excel worksheet on the client in a test website (not using IIS,...
0
by: jwmaiden | last post by:
Have an application that opens up a webbrowser control to display data in an Excel spreadsheet (using VB.NET in VS 2005). No problem with opening the spreadsheet or displaying the data, but I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.