frank-in-bahia
Member
- Joined
- Oct 6, 2013
- Messages
- 7
- Programming Experience
- Beginner
I know this isn't an unusual question, but in the dozens of posts I've read on the subject, I haven't found a solution.
My goal is simple: to paste some data from the Clipboard in VB to an existing Excel spreadsheet . . . appending to data already in the sheet. It's that last part that's giving me problems.
As per the code below (which works perfectly), I can open and copy to the worksheet with no problem, but I don't know how to essentially append, rather than overwrite the data already in the sheet.
I think the solution has something to do with finding the last row of existing data and then replacing Range("A1") with "A-whatever the next row is". But I haven't been able to find or craft the code to do it.
I'm using Visual Studio Express 2012, in a Windows Forms Application.
Many thanks!
Frank
My goal is simple: to paste some data from the Clipboard in VB to an existing Excel spreadsheet . . . appending to data already in the sheet. It's that last part that's giving me problems.
As per the code below (which works perfectly), I can open and copy to the worksheet with no problem, but I don't know how to essentially append, rather than overwrite the data already in the sheet.
VB.NET:
Dim sData As String
sData = ("test1" & vbTab & "test2" & vbTab & "test3")
Clipboard.Clear()
Clipboard.SetText(sData)
Dim xl = CreateObject("Excel.Application")
xl.workbooks.open("C:\test\Book2.xls") 'here's where I need to find the last row and replace Range("A1") in next line
xl.workbooks(1).Sheets(1).Range("A1").Select()
xl.workbooks(1).Sheets(1).Paste()
xl.application.displayalerts = False
xl.workbooks(1).Save()
xl.application.displayalerts = True
xl.quit()
xl = Nothing
I think the solution has something to do with finding the last row of existing data and then replacing Range("A1") with "A-whatever the next row is". But I haven't been able to find or craft the code to do it.
I'm using Visual Studio Express 2012, in a Windows Forms Application.
Many thanks!
Frank