-4

I am reading a .csv database in excel, because I am using an external database.

I dont want to copy anything into the excel application, I either want to read from the database(and maybe change some values), or add to it.

I have a textbox in a userform that should get the value of the last entry in "column" A(A reference number), and add one to it(this is for the next entry in the database).

I want to find the last row in a semicolon split CSV database using excel VBA.

Here is what I have so far:

Dim FilePath As String

FilePath = "L:\database.csv"
Open FilePath For Input As #1
    Do While Not EOF(1)
        linenumber = linenumber + 1
        Line Input #1, Line
        arrayOfElements = Split(Line, ";")

        elementnumber = 0

        testValue = arrayOfElements(0)

        If testValue = "L51599" Then

           refnr.Text = testValue
        Else
            'do nothing
        End If

    Loop
Close #1

Any tips?

Thanks

Thomas
  • 305
  • 1
  • 3
  • 11

1 Answers1

2

There are 5 different ways to that here : http://www.thespreadsheetguru.com/blog/2014/7/7/5-different-ways-to-find-the-last-row-or-last-column-using-vba.

Be aware of the fact that CSV files are not excel files and they cannot contain custom VBA functions (Macros). You will have to create your "findLastRow" function in a global template and assign it to a custom button on one of the toolbars/ribbons. this is explained here : https://msdn.microsoft.com/en-us/library/office/ee767705(v=office.14).aspx.

good luck!

FunkSoulBrother
  • 2,057
  • 18
  • 27