alex101fishing
Member
- Joined
- Dec 30, 2011
- Messages
- 18
- Programming Experience
- 3-5
First of all hello to all the members of this forum, I have only just joined and I am hopeful somebody might be able to spend 2 minutes looking at this for me.
I am an electronic engineer, however I have been roped in by a family member to make a little piece of software for a company, that will allow them to enter client information into a form, and have it written into a spreadsheet (for storage and access purposes), this data will then be processed into various reports over time. Sadly my degree did not include any form of VB! And I thought to myself it can't be that hard, and to be honest so far it had gone well. I have managed to make a form with the appropriate drop down boxes, I am able to create a new spreadsheet, format the spread sheet and place values in appointed cells. I have got the program testing the directory where I want the spreadsheets be to be stored and it is even able to test the file names of the spreadsheet to find a date corresponding with a search parameter set by the user.
However here comes my problem, the program needs to be able to add rows of data into a spreadsheet that has already been created, this I have managed to do with the code I have posted below: however I need to find a way of identifying the last row that contains any data within the worksheet, and then dropping the new data into the row after that. Hopefully that makes sense to you! I have been scouring the internet and have found various methods of doing this however none of them seem to work very well.
the method I found that almost seems to work is shown below: However it’s a bit hit and miss, it puts the data in row 10 for example when there is nothing after row 2. And then if I run it again it just replaces the data that it put in row 10, rather than going to next empty row.
So you know I am using Visual Studio 2011 Prof, thanks for any help!
'----------------Open existing Spreadsheet ----------------------------------
Dim new_app AsNew Microsoft.Office.Interop.Excel.Application
new_app.Visible = False
Dim new_book = new_app.Workbooks.Open(file_path & file_name)
Dim new_sheet = new_book.Worksheets(1).activate
'---------------Identify which row is the last-------------------------------
Dim LastRow = new_app.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row
'--------------Assign the individual records to each cell------------------------
new_app.Range("A" & LastRow).select()
new_app.ActiveCell.FormulaR1C1 = Surename
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
I am an electronic engineer, however I have been roped in by a family member to make a little piece of software for a company, that will allow them to enter client information into a form, and have it written into a spreadsheet (for storage and access purposes), this data will then be processed into various reports over time. Sadly my degree did not include any form of VB! And I thought to myself it can't be that hard, and to be honest so far it had gone well. I have managed to make a form with the appropriate drop down boxes, I am able to create a new spreadsheet, format the spread sheet and place values in appointed cells. I have got the program testing the directory where I want the spreadsheets be to be stored and it is even able to test the file names of the spreadsheet to find a date corresponding with a search parameter set by the user.
However here comes my problem, the program needs to be able to add rows of data into a spreadsheet that has already been created, this I have managed to do with the code I have posted below: however I need to find a way of identifying the last row that contains any data within the worksheet, and then dropping the new data into the row after that. Hopefully that makes sense to you! I have been scouring the internet and have found various methods of doing this however none of them seem to work very well.
the method I found that almost seems to work is shown below: However it’s a bit hit and miss, it puts the data in row 10 for example when there is nothing after row 2. And then if I run it again it just replaces the data that it put in row 10, rather than going to next empty row.
So you know I am using Visual Studio 2011 Prof, thanks for any help!
'----------------Open existing Spreadsheet ----------------------------------
Dim new_app AsNew Microsoft.Office.Interop.Excel.Application
new_app.Visible = False
Dim new_book = new_app.Workbooks.Open(file_path & file_name)
Dim new_sheet = new_book.Worksheets(1).activate
'---------------Identify which row is the last-------------------------------
Dim LastRow = new_app.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row
'--------------Assign the individual records to each cell------------------------
new_app.Range("A" & LastRow).select()
new_app.ActiveCell.FormulaR1C1 = Surename
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Last edited: