473,241 Members | 1,616 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,241 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 9734
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.