I know that my english can be better. Please rate my work and not my lack in linguistic skills!

If you find any kind of ownership issue, or you think some content is your property. Please be so kind and contact me, i will remove or solve it ASAP.

You like my free Uploads and want to support me, than please donate here:

Version for console applications

Imports System.Globalization
Imports Microsoft.Office.Interop.Excel

Private Sub Excel_export()
    Dim objExcelWbk As Microsoft.Office.Interop.Excel.Workbook
    Dim objExcelsht As Microsoft.Office.Interop.Excel.Worksheet
    Dim objExcelApp As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
    objExcelWbk = objExcelApp.Workbooks.Open("c:\tmp\vorlage.xlsx")
    objExcelsht = objExcelWbk.Sheets(1)
    objExcelsht.Range("A1").Value = "test"
    Try
        objExcelApp.objExcelWbk.objExcelsht.range("A1").value = "test"
    Catch ex As Exception
    End Try
End Sub

Alternative version with Form1+Button1

Imports System.Globalization
Imports Microsoft.Office.Interop.Excel

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim objExcelWbk As Microsoft.Office.Interop.Excel.Workbook
        Dim objExcelsht As Microsoft.Office.Interop.Excel.Worksheet
        Dim objExcelApp As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
        objExcelWbk = objExcelApp.Workbooks.Application.ActiveWorkbook
        'objExcelWbk = objExcelApp.Workbooks.Open("c:\tmp\vorlage.xlsx")
        objExcelsht = objExcelWbk.Sheets(1)
        objExcelsht.Range("A1").Value = "test"
        Try
            objExcelApp.objExcelWbk.objExcelsht.range("A1").value = "test"
        Catch ex As Exception
        End Try
    End Sub
End Class

CodeSample

Imports System.Globalization
Imports Microsoft.Office.Interop.Excel

Public Class Form1
    Dim objExcelWbk As Microsoft.Office.Interop.Excel.Workbook
    Dim objExcelsht As Microsoft.Office.Interop.Excel.Worksheet
    Dim objExcelApp As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")

    Dim rw As Integer = 1

    Dim tgtcolm As Integer '= 21
    Dim tgtcell As String
    Dim LstBaseColm As Integer
    Dim LastRow As Long

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        objExcelWbk = objExcelApp.Workbooks.Application.ActiveWorkbook
        'objExcelWbk = objExcelApp.Workbooks.Open("c:\tmp\vorlage.xlsx")
        objExcelsht = objExcelWbk.Sheets(1)
        '----------------------------------  searching tgtcolm ---------------------------------
        tgtcell = objExcelsht.Cells(1, 1).Value
        While tgtcell <> ""
            tgtcolm = tgtcolm + 1
            tgtcell = objExcelsht.Cells(1, tgtcolm).Value
        End While
        LstBaseColm = tgtcolm
        'tgtcolm = tgtcolm + 1
        '-------------------------------------- find last row ----------------------------------
        With objExcelsht
            While objExcelsht.Cells(rw, 2).value IsNot Nothing
                Dim test As String = objExcelsht.Cells(rw, 2).value.ToString
                rw = rw + 1
            End While
            LastRow = rw - 1
        End With
        MsgBox(LastRow)
    End Sub
End Class