Hello,
p45cal thanks for your reply. I mean without the macro record function, but the way with the Data Tab would be too easy haha.
I imported the .csv file with the following code:
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Public Sub download_und_import_bitcoin_courses()
If download_file <> 0 Then
MsgBox "Problem beim herunterladen.", vbExclamation
Exit Sub
End If
Call import
MsgBox "Import erfolgreich.", vbInformation
End Sub
Private Function download_file() As Long
Dim strURL As String
Dim strLocalFile As String
'Link zum Donwload
strURL = "here is the link to the .csv file, but I can´t paste it"
'Pfad für den Speicherort
strLocalFile = ThisWorkbook.Path & "\Bitcoin_" & Format(Date, "YYYYMMDD") & ".csv"
'Datei herunterladen und Status zurückgeben
download_file = URLDownloadToFile(0, strURL, strLocalFile, 0, 0)
End Function
Private Sub import()
Dim fso As Object
Dim txtStream As Object
Dim i As Integer, j As Integer
Dim strPfad As String
Dim strDaten() As String
Dim wksImport As Worksheet
'Tabelle, in der importiert wird
Set wksImport = Worksheets("Tabelle1")
'Bereich in dem Eingefügt wird (1,1 = A1; 2,1 = A2..)
i = 1: j = 1
'Tabellenblatt leeren
wksImport.Cells.Clear
strPfad = ThisWorkbook.Path & "\Bitcoin_" & Format(Date, "YYYYMMDD") & ".csv"
Set fso = CreateObject("Scripting.FilesystemObject")
Set txtStream = fso.OpenTextfile(strPfad)
Do While Not txtStream.AtEndOfStream
strDaten() = Split(txtStream.ReadLine, ",")
For j = 0 To UBound(strDaten())
wksImport.Cells(i, j + 1) = strDaten(j)
Next j
i = i + 1
Loop
txtStream.Close
Set txtStream = Nothing
Set fso = Nothing
End Sub
Function average (n As Integer) As Double
Dim arr As Range
Dim v As Variant
Dim sum As Double
Set arr = Range("E2:E22")
For Each v In arr
sum = sum + v
Next
average = sum / n
End Function
But the Function to calculate the average, won´t work. The first row is correct, but the second, third and so on is the same. Any ideas?
Thanks a lot
kind regards!