471,122 Members | 1,098 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 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 9612
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Chris Bellini | last post: by
5 posts views Thread by mrid via DotNetMonster.com | last post: by

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.