473,382 Members | 1,526 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,382 software developers and data experts.

Excel Range will not put data into correct Cell

Hello everyone - new to VB.net working with Excel

I am trying to populate data into cells in an Excel spreadsheet using
Range.Value. No matter what cell I give as an argument to the Range
object, Excel always puts the value in "A1".

Here is the code I am having problems with. I am not getting any
errors.

oWBK = oXL.Workbooks.Open("C:\Data.xls")
oWS = oXL.Worksheets(1)
oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!"

The resulting Excel sheet will have the text "PUT IT IN THE RIGHT
SPOT!!!" in Cell "A1".

What am I doing wrong?

Thanks

Jan 20 '06 #1
6 1571
Hi,

Although this is probably for VBNet, will asking this kind of questions
first in the one of the most active newsgroups

microsoft.public.excel.programmer

Give you an better change on an answer and if it than does not fit in VBNet
ask it here.

I hope this helps,

Cor
"XxLicherxX" <go********@aol.com> schreef in bericht
news:11*********************@g43g2000cwa.googlegro ups.com...
Hello everyone - new to VB.net working with Excel

I am trying to populate data into cells in an Excel spreadsheet using
Range.Value. No matter what cell I give as an argument to the Range
object, Excel always puts the value in "A1".

Here is the code I am having problems with. I am not getting any
errors.

oWBK = oXL.Workbooks.Open("C:\Data.xls")
oWS = oXL.Worksheets(1)
oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!"

The resulting Excel sheet will have the text "PUT IT IN THE RIGHT
SPOT!!!" in Cell "A1".

What am I doing wrong?

Thanks

Jan 20 '06 #2
How about this syntax:
if you can gain access to the Cells collection, you should be able to do
something like:

Cells(row, col).Value = "My good value"

HTH
Steve

"XxLicherxX" <go********@aol.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hello everyone - new to VB.net working with Excel

I am trying to populate data into cells in an Excel spreadsheet using
Range.Value. No matter what cell I give as an argument to the Range
object, Excel always puts the value in "A1".

Here is the code I am having problems with. I am not getting any
errors.

oWBK = oXL.Workbooks.Open("C:\Data.xls")
oWS = oXL.Worksheets(1)
oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!"

The resulting Excel sheet will have the text "PUT IT IN THE RIGHT
SPOT!!!" in Cell "A1".

What am I doing wrong?

Thanks

Jan 20 '06 #3
Hey Guys,

Thanks for your responses. I have worked on it a little more and the
problem seems to be with the way I create the Excel file. I was doing
this:

FileOpen(1,"C:\data.xls")
FileClose(1)

when I commented this stuff out, everything started working correcly,
however, I need to be able to create a new file from this application.
So I tried using

Sub CreateXLFile()

Dim oExcel = CreateObject("Excel.Application")

With oExcel
.SheetsInNewWorkbook = 3
oExcel = .Workbooks.Add
.Save("C:\Data.xls")
.Quit()
End With

End Sub

That does not work. It creates the file just fine, but does not write
to it. This is what I am using to write to the file: (Same as Above)

oWBK = oXL.Workbooks.Open("C:\Data.xls")
oWS = oXL.Worksheets(1)
oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!"

I then open the excel file and it is blank. The only time I can get
this to work correctly is if I manually create the file using Windows
Explorer ("Right Click -> Excel File, etc).

What am I doing wrong again?

Thanks

Jan 20 '06 #4
Ok, I looked around a bit more and it is in fact writing data, however
it is saving it to the My Documents folder under Book1.xls, Book2.xls,
etc. This doesn't make any sense to me. I never specify the My
Documents directory anywhere in the program. Also when the program is
running I get a prompt telling me that "C:\Data.xls" already exists and
would I like to replace it.

Jan 20 '06 #5
This might help
http://support.microsoft.com/?scid=kb;EN-US;301982

If not I have demo code, let me know.

"XxLicherxX" <go********@aol.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hello everyone - new to VB.net working with Excel

I am trying to populate data into cells in an Excel spreadsheet using
Range.Value. No matter what cell I give as an argument to the Range
object, Excel always puts the value in "A1".

Here is the code I am having problems with. I am not getting any
errors.

oWBK = oXL.Workbooks.Open("C:\Data.xls")
oWS = oXL.Worksheets(1)
oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!"

The resulting Excel sheet will have the text "PUT IT IN THE RIGHT
SPOT!!!" in Cell "A1".

What am I doing wrong?

Thanks

Jan 23 '06 #6
Thanks Kevin,

That will come in handy.

Jan 24 '06 #7

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
7
by: Hugh McLaughlin | last post by:
Hello Everyone and thanks for your help in advance. I am working on an application that requires the parsing of an Excel spreadsheet that will be loaded into a SQL Server table. An example of...
1
by: barma16 | last post by:
I've hit a bit of a brick wall here, and could use some advice. I have an Access application whose output is a four-tab Excel spreadsheet where three of the four tabs are the result of database...
3
by: Carlos Magalhaes | last post by:
Hey All, I am doing some excel automation using the excel COM. I can do most of the functions and its working well until I come across a formula. I can run a formula and insert the formula...
6
by: Elena | last post by:
I'm trying to export data to an Excel worksheet. I can export the data in the cell values perfectly. I need the code to change a header and footer for the worksheet, not for the columns. Is...
18
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a...
2
by: krigare | last post by:
Hope this is the right place to post :-) I am trying to use an Excel COM object via PHP. I am able to read/write data to cells, use AutoFilter, and AutoFit on columns. I can even set the cell...
3
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to...
3
by: toffee | last post by:
Hi all, I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.