|
-
Mar 17th, 2005, 02:16 PM
#1
Thread Starter
New Member
Writing to Excel
I'm doing a project and I need to write data from textboxes to an Excel file. There is already data in the Excel file, but how can I check which row is the first empty one and then write the data to that row.
greetz
-
Mar 17th, 2005, 02:22 PM
#2
Re: Writing to Excel
If you can assume that each row in column x has data, such that the first empty one is the one you want to write in, you can loop through the cells in that column (I think that would be cells(rowNumber,colNumber), but I can't check it right now) looking for the empty one.
However, this is best if it only happens once. If you will be writing many times, it would be best to keep the next row to write to (or last one written to) as a variable in the program. Figure it out once, then manage it in code.
My usual boring signature: Nothing
 
-
Mar 23rd, 2005, 03:36 AM
#3
Thread Starter
New Member
Re: Writing to Excel
This code I used, but somehow it only worked once. Afterwords I did some changes, maybe that has been the problem.
And I've got another question, how could you automaticly save the changes you make in the excel file.
VB Code:
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim Lrow As Integer
Dim x As Integer
Lrow = xlBlad.UsedRange.Rows.Count
x = Lrow + 1
' input data naar Excel
xlBlad.Cells(x, 1) = monthcalender.SelectionStart
xlBlad.Cells(x, 2) = txtaantalkm.Text
xlBlad.Cells(x, 3) = txttijd.Text
xlBlad.Cells(x, 4) = minkm.ToString
xlBlad.Cells(x, 5) = kmperuur.ToString
xlBlad.Cells(x, 6) = cbosoort.Text
End Sub
Private Sub Toevoegen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If strkeuze = "Ma" Then
mstrBestand = Application.StartupPath & "\" & "looptijdenMA.xls"
Else
mstrBestand = Application.StartupPath & "\" & "looptijdenPA.xls"
End If
xlToepassing = xlGlobale.Application
xlBook = xlToepassing.Workbooks.Open(mstrBestand)
xlBlad = xlToepassing.ActiveSheet
End Sub
Private Sub Toevoegen_Unload(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
xlToepassing.Quit()
xlToepassing = Nothing
xlBook = Nothing
xlBlad = Nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|