When I run the code on one of my files it deletes most of the lines and leaves me with the lines where I was at about 1100 hMSL and below.
I think that was the reason why it also chrashed later in "code1" without feedback on why.
Also it opened three workbooks on my computer.
One beeing the codeworkbook, one called "book1" and then one with the gps-data. Then it closed one (I think it was "book1").
I think the reason you can't "call" on the correct workbook is because you use "ActiveWorkbook".
When you push button2, "ActiveWorkbook" becomes the macro-workbook.
Instead I think you should use something like this:
At the very top add public wb as workbook :
Option Explicit
Public wb As Workbook
Private Sub CommandButton1_Click()
Somewhere in the button1_click where you know it's running in the correct workbook add :
Now wb is the workbook.
So for example msgbox wb.name will output the name of the workbook.
In button2_click you could now use a simple wb.Activate to make sure Excel focuses on the correct workbook.
This means all the ActiveWorkbooks and ActiveSheets should point in the correct direction.
BUT.
It's not a good solution really.
You should try to avoid ActiveWorkbook and ActiveSheet as much as possible.
wb. or ws. is much better.
This means you need to define wb as workbook and ws as worksheet.
However I still believe a much nicer solution is a Add-in file that runs in the background.
A Add-in can be programmed to only respond to CSV-files with the correct content.
Bookmarks