Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2012 How to Write Data to Excel 1 Row down on each click ?

$
0
0
Im writing a simple Windows Form Application for my business and so far have been pretty successful.
(This is my first interaction with VB ever lol) Ive hit a little snag in the road however. Im using this App to export data to an Excel Workbook. So far im very successful at doing this and saving it. However im doing it manually (Cell by cell ie. Range("C1") = Textbox.text) Im fine with this until i hit a section of data that needs to be exported that will take up 5 columns and 30 Rows. This would be fine however i need to export it to the same sheet everytime the button is pressed. So my question is can i use a code to maybe tell it to write the data to the next line down on each button click. I came across a code that looked promising however im getting an Error.

Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Dim LastRow As Long


oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open("C:\Users\Jbenedettini\Desktop\Testexcel.xls")
LastRow = Range("A65536").End("Xlup").Row + 1

oSheet = oBook.Worksheets(2)
oSheet.Range("A" & LastRow).Value = TextBox1.Text
oSheet.Range("B" & LastRow).Value = ComboBox1.Text


This code gives me an error of
'System.Data.Range' is not accessible Form1.Vb in this context because it is 'Friend'.

Any help is appreciated, figured i would try here before i start manually doing line by line 600 lines lol
Thanks

Viewing all articles
Browse latest Browse all 27554

Trending Articles