473,406 Members | 2,713 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,406 software developers and data experts.

referencing cells in Excel and finding empty cells


I'm moving some code from Excel vbs into a .NET context and I'm very
new to .NET. I'm trying to make this Excel vb code work in .NET. My
questions are: how do I reference cells correctly using the common
"cells(x,y)" reference, where x and y are integer variables. Also, how
do I verify that the cells are empty, since, according to the
documentation, the "IsEmpty" function does not work in .NET now?

Thanks for any help!

'//////////START CODE EXAMPLE///////////

Function getroworcol(roworcol, start)

Dim intoutside As Integer
Dim intctr

'DETERMINE START POINT OF SEARCH
If roworcol = 0 Then
outside = 200
Else
outside = 50
End If

'COUNT BACKWARDS FROM START POINT UNTIL FIND FILLED CELL
For intctr = outside To 1 Step -1
If roworcol = 0 Then
If IsEmpty(Cells(intctr, 1)) = False Then
Exit For
End If
ElseIf roworcol = 1 Then
If IsEmpty(Cells(1, intctr)) = False Then
Exit For
End If
End If
Next intctr

getroworcol = intctr

End Function

'////END CODE////////

May 29 '06 #1
1 9747
Hello, mgoold2002,

Using "Cells" is essentially the same as in Excel VBA, except that you
will need to apply it to an object (rather than using the "default").
Perhaps you can replace IsEmpty by comparing the Formula with an empty
string, as in the example below:

Dim xlapp As Excel.Application
xlapp = CType(CreateObject("Excel.Application"), _
Excel.Application)
Dim wb As Excel.Workbook = _
xlapp.Workbooks.Open("J:\Test\ExcelTest\Test.xls")
Dim xlSheet As Excel.Worksheet = wb.Worksheets(1)
Dim currRow As Integer = 1
xlSheet.Cells(currRow, 1) = 1.23
xlSheet.Cells(currRow, 2) = "AB.CD"
xlSheet.Cells(currRow, 3) = Now
If (xlSheet.Cells(currRow, 4).Formula = "") Then
MsgBox("It's empty!")
End If
wb.Save()
wb.Close()
xlapp.Quit()

Cheers,
Randy
mg********@hotmail.com wrote:
I'm moving some code from Excel vbs into a .NET context and I'm very
new to .NET. I'm trying to make this Excel vb code work in .NET. My
questions are: how do I reference cells correctly using the common
"cells(x,y)" reference, where x and y are integer variables. Also, how
do I verify that the cells are empty, since, according to the
documentation, the "IsEmpty" function does not work in .NET now?

Thanks for any help!

'//////////START CODE EXAMPLE///////////

Function getroworcol(roworcol, start)

Dim intoutside As Integer
Dim intctr

'DETERMINE START POINT OF SEARCH
If roworcol = 0 Then
outside = 200
Else
outside = 50
End If

'COUNT BACKWARDS FROM START POINT UNTIL FIND FILLED CELL
For intctr = outside To 1 Step -1
If roworcol = 0 Then
If IsEmpty(Cells(intctr, 1)) = False Then
Exit For
End If
ElseIf roworcol = 1 Then
If IsEmpty(Cells(1, intctr)) = False Then
Exit For
End If
End If
Next intctr

getroworcol = intctr

End Function

'////END CODE////////

May 30 '06 #2

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

Similar topics

3
by: zxo102 | last post by:
Hi there, I need your help for python <--> excel. I want to paste selected cells (range) to different location on the same sheet in Excel through python. I have tried it for a while but could not...
2
by: Wendy Spray | last post by:
Hi I have an xml document that has been created from an excel spreadsheet. In the s/s there are some empty cells however these are not captured in the xml file. All that is added is for the cell...
2
by: Chris Bellini | last post by:
Greetings! I'm developing a C# application that needs to read some data from a selected XLS file. I've used VB in the past to automate Excel but this is the first time I've used C#. Back in VB,...
1
by: Glen Vermeylen | last post by:
Hi, For a project at school we have to automate the assignment of seats in classrooms to students during the exams. The lady who previously did everything manually kept the layouts of the...
5
by: mrid via DotNetMonster.com | last post by:
hi. im exporting data from a vb form to excel. i am able to create a new excel file, save and edit it without any trouble, but the formatting is giving me hell! i need to be able to show certain...
8
by: Edgar | last post by:
Tools: SQL Server 2K, Excel 2000 Hi, I have an Excel report worksheet with formatted headings. What I want to do is to export data from the SQL server into a specific cell of the excel file....
0
by: Starter in VBA | last post by:
HELP! Need your help in finding how to creating charts with dynamic ranges of cells which are referenced to by variables indicating the beginning and ending of row and column numbers. My...
4
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I...
2
by: Stratocaster | last post by:
Hello, and thank you for any help in advance. I need help determining if any commands exist in VB (Excel macro style) that can enable a user to select cells and run a macro which performs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.