Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This I think is a simple solution. Just that I have spent too long trying to do it.

I have a worksheet named, "SheetA" and have headings from A1....D1 e.g. forename, surname, department, age

I want to copy and paste this line into my other worksheet "SheetB" at the same place.

How is this done?
Posted

 
Share this answer
 
Comments
Maciej Los 8-Apr-13 14:11pm    
This is for VBA, not for VB.NET ;(
Kenneth Haugland 8-Apr-13 14:52pm    
I know, that is true, but they are easily converted. :-)
Maciej Los 8-Apr-13 14:57pm    
I know, i expected that you reply me this way ;)
Kenneth Haugland 8-Apr-13 15:12pm    
Google is rather predictable, I know :laugh:
Using late binding ;)
VB
Dim oExc As Object = Nothing, oWbk As Object = Nothing
Dim oSrcWsh As Object = Nothing, oDstWsh As Object = Nothing

Try
    oExc = CreateObject("Excel.Applictaion")
    oWbk = oExc.Workbooks.Open("FullPathToWorkbook.xls")

    oSrcWsh = oWbk.WorkSheets("Sheet1")
    oDstWsh = oWbk.WorkSheets("Sheet2")

    oSrcWsh.Range("A1:D1").Copy(oDstWsh.Range("A1"))
    oWbk.Save()

Catch ex As Exception
    Console.WriteLine(ex.Message)

Finally
    oSrcWsh = Nothing
    oDstWsh = Nothing
    oWbk.Close(SaveChanges:=False)
    oWbk = Nothing
    oExc.Quit()
    oExc = Nothing
End Try
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900