Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1004to1008
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Import Text Files

Import Text Files
25.08.2008 15:30:00
mehmet
Hallo Forum,
dank Macrorecorder konnte ich folgendes aufzeichnen:

Hier die Datei: https://www.herber.de/bbs/user/54888.xls
oder der Code:

Sub Einlesen_MitTabMitTxtInSpalte()
Columns("B:z").Select
Selection.Delete Shift:=xlToLeft
Range("B1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & Cells(2, 1) & ".TXT" _
_
_
, _
Destination:=Range("b2"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & Cells(5, 1) & ".TXT" _
_
_
, _
Destination:=Range("b5"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & Cells(8, 1) & ".TXT" _
_
_
, _
Destination:=Range("b8"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & Cells(11, 1) & ". _
TXT", _
Destination:=Range("b11"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub


Wie kann man dies als eine Schleife eleganter lösen?
Dank und Gruss
mehmet

16
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Schleife!
25.08.2008 16:15:53
Backowe
Hi,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim i As Integer
Columns("B:Z").Delete Shift:=xlToLeft
For i = 2 To 11 Step 3
  With ActiveSheet.QueryTables.Add(Connection:="TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
    Cells(i, 1) & ".TXT", Destination:=Range("B" & i))
    .Name = ""
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = False
    .RefreshOnFileOpen = False
    .RefreshStyle = xlOverwriteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = False
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 850
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = True
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = True
    .TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
  End With
Next
End Sub
Gruß Jürgen
AW: Schleife!
mehmet

Hallo Jürgen,
du bist super, Dank dir.
Kannst du mir noch zeigen, wie ich aus so einer Tabelle ein Matrixähnliche Tabelle erstellen kann.
D.H.:
Spalte B soll das Datum stehen (Zeile1 aus dem Internet)
Spalte A soll die Uhrzeit stehen (Zeile 1 aus dem Internet)
Spalte C bis ? soll das stehen, was aus dem Internet (Zeile2) gesaugt wurde
(Bsp. für EDDK: B3-Z3)
Dank und Gruss
mehmet
Ich habe ein Verständnisproblem!
Backowe

Hi mehmet,
wie sieht denn ein Beispiel aus nach dem Download? Kann ich mir jetzt nicht vorstellen.
Gruß Jürgen
AW: Ich habe ein Verständnisproblem!
mehmet

Hier ein Beispiel:
https://www.herber.de/bbs/user/54892.xls
Alles untereinder und sortiert.
Es handelt sich hier um Wetterabfrage aus dem Netz für einige Flughäfen
Der Format ist immer (sollte) gleich sein
Dank dir im Voraus
Gruss
mehmet
AW: Ich habe ein Verständnisproblem!
Backowe

Hi mehmet,
die Datei die Du hochgeladen hast, ist scheinbar das Endprodukt wie die Datei zum Schluß aussehen soll. Aber was mir fehlt sind die Rohdaten direkt nach dem Download, wie sieht da die Datei aus, sonst weiß ich ja nicht was ich anpassen soll.
Gruß Jürgen
AW: Ich habe ein Verständnisproblem!
mehmet

Sorry, hier die Dateien:
https://www.herber.de/bbs/user/54894.txt für Berlin (EDDB)
https://www.herber.de/bbs/user/54895.txt für Köln (EDDK)
https://www.herber.de/bbs/user/54896.txt für Düsseldorf (EDDL)
https://www.herber.de/bbs/user/54897.txt für München (EDDM)
Gruss
mehmet
So sollte es jetzt passen!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen2_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer
Columns("B:Z").Delete Shift:=xlToLeft
For i = 2 To 5
  With ActiveSheet.QueryTables.Add(Connection:="TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
    Cells(i, 1) & ".TXT", Destination:=Range("B" & i))
      .Name = ""
      .FieldNames = True
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = False
      .RefreshOnFileOpen = False
      .RefreshStyle = xlOverwriteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = False
      .RefreshPeriod = 0
      .TextFilePromptOnRefresh = False
      .TextFilePlatform = 850
      .TextFileStartRow = 1
      .TextFileParseType = xlDelimited
      .TextFileTextQualifier = xlTextQualifierDoubleQuote
      .TextFileConsecutiveDelimiter = True
      .TextFileTabDelimiter = True
      .TextFileSemicolonDelimiter = False
      .TextFileCommaDelimiter = False
      .TextFileSpaceDelimiter = True
      .TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
      .TextFileTrailingMinusNumbers = True
      .Refresh BackgroundQuery:=False
    End With
  Next
  ImportZeile = Cells(i, "B") & " " & Cells(i + 1, "B")
  Range(Cells(i, "B"), Cells(i + 1, "B")).ClearContents
  Ergebnis = Split(ImportZeile, " ")
    For j = 0 To UBound(Ergebnis)
      Cells(i, j + 2) = Ergebnis(j)
    Next
Next
End Sub
Gruß Jürgen
Kleiner Fehler berichtigt!
Backowe

Hi mehmet,
in die For-Schleife hatte sich ein kleiner Fehler eingeschlichen! ;o)
VBA-Code:
Sub Einlesen2_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer
Range("B2:Z5").Delete Shift:=xlToLeft
For i = 2 To 5
  With ActiveSheet.QueryTables.Add(Connection:="TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
    Cells(i, 1) & ".TXT", Destination:=Range("B" & i))
      .Name = ""
      .FieldNames = True
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = False
      .RefreshOnFileOpen = False
      .RefreshStyle = xlOverwriteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = False
      .RefreshPeriod = 0
      .TextFilePromptOnRefresh = False
      .TextFilePlatform = 850
      .TextFileStartRow = 1
      .TextFileParseType = xlDelimited
      .TextFileTextQualifier = xlTextQualifierDoubleQuote
      .TextFileConsecutiveDelimiter = True
      .TextFileTabDelimiter = True
      .TextFileSemicolonDelimiter = False
      .TextFileCommaDelimiter = False
      .TextFileSpaceDelimiter = True
      .TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
      .TextFileTrailingMinusNumbers = True
      .Refresh BackgroundQuery:=False
    End With
  ImportZeile = Cells(i, "B") & " " & Cells(i + 1, "B")
  Range(Cells(i, "B"), Cells(i + 1, "B")).ClearContents
  Ergebnis = Split(ImportZeile, " ")
    For j = 0 To UBound(Ergebnis)
      Cells(i, j + 2) = Ergebnis(j)
    Next
Next
End Sub
AW: Kleiner Fehler berichtigt!
mehmet

Dank dir Jürgen,
beim einlesen werden die anderen Daten überschrieben statt versetzt.
Hier die Datei:
https://www.herber.de/bbs/user/54899.xls
Eine andere Frage:
1. Kann man es mit einem Datenfilter versehen und nur die Daten Downloaden, die auch zu sehen sind.
Also nicht die ganze Tabelle updaten.
2. Falls eine Fehlermeldung kommt: xxx Datei konnte nicht gefunden werden, diese dann unterdrücken und weiter mit der nächsten abfrage fortfahren (Bsp., Abbruch bei: LESJ).
Dank dir im Voraus
Gruss
mehmet
Ich habe es inzwischen gemerkt!
Backowe

Hi mehmet,
ich habe jetzt mal selbst die Abfrage eingerichtet und das Gleiche festgestellt! Habe jetzt aber keine Zeit mehr, morgen Mittag geht es weiter. ;o)
Gruß Jürgen
AW: Ich habe es inzwischen gemerkt!
mehmet

OK, txs
Neuer Anlauf!
Backowe

Hi mehmet,
ich habe Dich nicht vergessen! :)
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:L" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
Sheets.Add.Name = "Temp"
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A5").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
    .Columns("B").Delete
  End With
Next
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
Kleine letzte Korrektur!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A100").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
AW: Kleine letzte Korrektur!
mehmet

Hallo Jürgen,
was soll ich sagen, du bist super 8-)
Es funktioniert. Dank dir.
Leider sind die Daten nicht sortiert.
Wie könnte man diese noch sortieren?
Alles was mit ....KT oder .....MPS endet unter Wind/Grad (Punkte stehen für Zahlen, wobei ersten 3 Zahlen für Grad und folgend mit Knoten angegeben werden).
alles was mit ../.. oder ./. oder ../. oder ./.. unter Temperature/Dew Point (Temperatur/TauPunkt)
alles was nachfolgend mit Q... oder Q.... beginnt unter Pressure (Luftdruck)
alles was mit NOSIG unter Remarks Spalte.
Ich weis, dass es bischen kompliziert ist, aber eine Sortierung der Daten währe es toll!
Ist das Möglich?
Als Anhang habe ich die Tabelle2 (bereits downgeloaded) mit der Kopfzeile beschriftet.
https://www.herber.de/bbs/user/54935.xls
Dank im Voraus
Herzliche Grüsse
mehmet
Letztes Posting!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A200").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Sub Sortieren()
Dim Zelle As Range
Application.ScreenUpdating = True
With Sheets("Tabelle1")
  If .FilterMode Then .ShowAllData
  .Range("N2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(RIGHT(F2,2)=""KT"",RIGHT(F2,3)=""MPS"")"
  For Each Zelle In .Range("O2:O" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    If InStr(Zelle.Offset(0, -5), "/") > 0 Then
      Zelle.Value = True
    Else
      Zelle.Value = False
    End If
  Next
  .Range("P2:P" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(Left(K2,1)=""Q"",LEFT(L2,5)=""NOSIG"")"
  'Beim Sortieren gibt es 3 Möglichkeiten, ich habe "Q" und "NOSIG" zusammengefasst, wenn es nicht passen sollte,
  'einfach anpassen!
  .Range("A2:Q" & .Cells(.Rows.Count, "A").End(xlUp).Row).Sort Key1:=.Range("N2"), Order1:=xlDescending, Key2:=.Range("O2") _
    , Order2:=xlDescending, Key3:=.Range("P2"), Order3:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
  .Columns("N:P").Delete shift:=xlLeft
End With
Application.ScreenUpdating = False
End Sub
Gruss Jürgen
AW: Letztes Posting!
mehmet

Hallo Jürgen,
ich danke dir für deine Hilfe
Gruss
mehmet
Anzeige
AW: Schleife!
25.08.2008 16:30:18
mehmet
Hallo Jürgen,
du bist super, Dank dir.
Kannst du mir noch zeigen, wie ich aus so einer Tabelle ein Matrixähnliche Tabelle erstellen kann.
D.H.:
Spalte B soll das Datum stehen (Zeile1 aus dem Internet)
Spalte A soll die Uhrzeit stehen (Zeile 1 aus dem Internet)
Spalte C bis ? soll das stehen, was aus dem Internet (Zeile2) gesaugt wurde
(Bsp. für EDDK: B3-Z3)
Dank und Gruss
mehmet
Ich habe ein Verständnisproblem!
25.08.2008 16:33:00
Backowe
Hi mehmet,
wie sieht denn ein Beispiel aus nach dem Download? Kann ich mir jetzt nicht vorstellen.
Gruß Jürgen
AW: Ich habe ein Verständnisproblem!
25.08.2008 16:49:50
mehmet
Hier ein Beispiel:
https://www.herber.de/bbs/user/54892.xls
Alles untereinder und sortiert.
Es handelt sich hier um Wetterabfrage aus dem Netz für einige Flughäfen
Der Format ist immer (sollte) gleich sein
Dank dir im Voraus
Gruss
mehmet
Anzeige
AW: Ich habe ein Verständnisproblem!
25.08.2008 17:04:00
Backowe
Hi mehmet,
die Datei die Du hochgeladen hast, ist scheinbar das Endprodukt wie die Datei zum Schluß aussehen soll. Aber was mir fehlt sind die Rohdaten direkt nach dem Download, wie sieht da die Datei aus, sonst weiß ich ja nicht was ich anpassen soll.
Gruß Jürgen
So sollte es jetzt passen!
25.08.2008 18:07:28
Backowe
Hi mehmet,
VBA-Code:
Sub Einlesen2_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer
Columns("B:Z").Delete Shift:=xlToLeft
For i = 2 To 5
  With ActiveSheet.QueryTables.Add(Connection:="TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
    Cells(i, 1) & ".TXT", Destination:=Range("B" & i))
      .Name = ""
      .FieldNames = True
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = False
      .RefreshOnFileOpen = False
      .RefreshStyle = xlOverwriteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = False
      .RefreshPeriod = 0
      .TextFilePromptOnRefresh = False
      .TextFilePlatform = 850
      .TextFileStartRow = 1
      .TextFileParseType = xlDelimited
      .TextFileTextQualifier = xlTextQualifierDoubleQuote
      .TextFileConsecutiveDelimiter = True
      .TextFileTabDelimiter = True
      .TextFileSemicolonDelimiter = False
      .TextFileCommaDelimiter = False
      .TextFileSpaceDelimiter = True
      .TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
      .TextFileTrailingMinusNumbers = True
      .Refresh BackgroundQuery:=False
    End With
  Next
  ImportZeile = Cells(i, "B") & " " & Cells(i + 1, "B")
  Range(Cells(i, "B"), Cells(i + 1, "B")).ClearContents
  Ergebnis = Split(ImportZeile, " ")
    For j = 0 To UBound(Ergebnis)
      Cells(i, j + 2) = Ergebnis(j)
    Next
Next
End Sub
Gruß Jürgen
Kleiner Fehler berichtigt!
Backowe

Hi mehmet,
in die For-Schleife hatte sich ein kleiner Fehler eingeschlichen! ;o)
VBA-Code:
Sub Einlesen2_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer
Range("B2:Z5").Delete Shift:=xlToLeft
For i = 2 To 5
  With ActiveSheet.QueryTables.Add(Connection:="TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
    Cells(i, 1) & ".TXT", Destination:=Range("B" & i))
      .Name = ""
      .FieldNames = True
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = False
      .RefreshOnFileOpen = False
      .RefreshStyle = xlOverwriteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = False
      .RefreshPeriod = 0
      .TextFilePromptOnRefresh = False
      .TextFilePlatform = 850
      .TextFileStartRow = 1
      .TextFileParseType = xlDelimited
      .TextFileTextQualifier = xlTextQualifierDoubleQuote
      .TextFileConsecutiveDelimiter = True
      .TextFileTabDelimiter = True
      .TextFileSemicolonDelimiter = False
      .TextFileCommaDelimiter = False
      .TextFileSpaceDelimiter = True
      .TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
      .TextFileTrailingMinusNumbers = True
      .Refresh BackgroundQuery:=False
    End With
  ImportZeile = Cells(i, "B") & " " & Cells(i + 1, "B")
  Range(Cells(i, "B"), Cells(i + 1, "B")).ClearContents
  Ergebnis = Split(ImportZeile, " ")
    For j = 0 To UBound(Ergebnis)
      Cells(i, j + 2) = Ergebnis(j)
    Next
Next
End Sub
AW: Kleiner Fehler berichtigt!
mehmet

Dank dir Jürgen,
beim einlesen werden die anderen Daten überschrieben statt versetzt.
Hier die Datei:
https://www.herber.de/bbs/user/54899.xls
Eine andere Frage:
1. Kann man es mit einem Datenfilter versehen und nur die Daten Downloaden, die auch zu sehen sind.
Also nicht die ganze Tabelle updaten.
2. Falls eine Fehlermeldung kommt: xxx Datei konnte nicht gefunden werden, diese dann unterdrücken und weiter mit der nächsten abfrage fortfahren (Bsp., Abbruch bei: LESJ).
Dank dir im Voraus
Gruss
mehmet
Ich habe es inzwischen gemerkt!
Backowe

Hi mehmet,
ich habe jetzt mal selbst die Abfrage eingerichtet und das Gleiche festgestellt! Habe jetzt aber keine Zeit mehr, morgen Mittag geht es weiter. ;o)
Gruß Jürgen
AW: Ich habe es inzwischen gemerkt!
mehmet

OK, txs
Neuer Anlauf!
Backowe

Hi mehmet,
ich habe Dich nicht vergessen! :)
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:L" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
Sheets.Add.Name = "Temp"
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A5").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
    .Columns("B").Delete
  End With
Next
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
Kleine letzte Korrektur!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A100").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
AW: Kleine letzte Korrektur!
mehmet

Hallo Jürgen,
was soll ich sagen, du bist super 8-)
Es funktioniert. Dank dir.
Leider sind die Daten nicht sortiert.
Wie könnte man diese noch sortieren?
Alles was mit ....KT oder .....MPS endet unter Wind/Grad (Punkte stehen für Zahlen, wobei ersten 3 Zahlen für Grad und folgend mit Knoten angegeben werden).
alles was mit ../.. oder ./. oder ../. oder ./.. unter Temperature/Dew Point (Temperatur/TauPunkt)
alles was nachfolgend mit Q... oder Q.... beginnt unter Pressure (Luftdruck)
alles was mit NOSIG unter Remarks Spalte.
Ich weis, dass es bischen kompliziert ist, aber eine Sortierung der Daten währe es toll!
Ist das Möglich?
Als Anhang habe ich die Tabelle2 (bereits downgeloaded) mit der Kopfzeile beschriftet.
https://www.herber.de/bbs/user/54935.xls
Dank im Voraus
Herzliche Grüsse
mehmet
Letztes Posting!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A200").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Sub Sortieren()
Dim Zelle As Range
Application.ScreenUpdating = True
With Sheets("Tabelle1")
  If .FilterMode Then .ShowAllData
  .Range("N2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(RIGHT(F2,2)=""KT"",RIGHT(F2,3)=""MPS"")"
  For Each Zelle In .Range("O2:O" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    If InStr(Zelle.Offset(0, -5), "/") > 0 Then
      Zelle.Value = True
    Else
      Zelle.Value = False
    End If
  Next
  .Range("P2:P" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(Left(K2,1)=""Q"",LEFT(L2,5)=""NOSIG"")"
  'Beim Sortieren gibt es 3 Möglichkeiten, ich habe "Q" und "NOSIG" zusammengefasst, wenn es nicht passen sollte,
  'einfach anpassen!
  .Range("A2:Q" & .Cells(.Rows.Count, "A").End(xlUp).Row).Sort Key1:=.Range("N2"), Order1:=xlDescending, Key2:=.Range("O2") _
    , Order2:=xlDescending, Key3:=.Range("P2"), Order3:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
  .Columns("N:P").Delete shift:=xlLeft
End With
Application.ScreenUpdating = False
End Sub
Gruss Jürgen
AW: Letztes Posting!
mehmet

Hallo Jürgen,
ich danke dir für deine Hilfe
Gruss
mehmet
Anzeige
Kleiner Fehler berichtigt!
25.08.2008 18:15:00
Backowe
Hi mehmet,
in die For-Schleife hatte sich ein kleiner Fehler eingeschlichen! ;o)
VBA-Code:
Sub Einlesen2_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer
Range("B2:Z5").Delete Shift:=xlToLeft
For i = 2 To 5
  With ActiveSheet.QueryTables.Add(Connection:="TEXT;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
    Cells(i, 1) & ".TXT", Destination:=Range("B" & i))
      .Name = ""
      .FieldNames = True
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = False
      .RefreshOnFileOpen = False
      .RefreshStyle = xlOverwriteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = False
      .RefreshPeriod = 0
      .TextFilePromptOnRefresh = False
      .TextFilePlatform = 850
      .TextFileStartRow = 1
      .TextFileParseType = xlDelimited
      .TextFileTextQualifier = xlTextQualifierDoubleQuote
      .TextFileConsecutiveDelimiter = True
      .TextFileTabDelimiter = True
      .TextFileSemicolonDelimiter = False
      .TextFileCommaDelimiter = False
      .TextFileSpaceDelimiter = True
      .TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
      .TextFileTrailingMinusNumbers = True
      .Refresh BackgroundQuery:=False
    End With
  ImportZeile = Cells(i, "B") & " " & Cells(i + 1, "B")
  Range(Cells(i, "B"), Cells(i + 1, "B")).ClearContents
  Ergebnis = Split(ImportZeile, " ")
    For j = 0 To UBound(Ergebnis)
      Cells(i, j + 2) = Ergebnis(j)
    Next
Next
End Sub
AW: Kleiner Fehler berichtigt!
mehmet

Dank dir Jürgen,
beim einlesen werden die anderen Daten überschrieben statt versetzt.
Hier die Datei:
https://www.herber.de/bbs/user/54899.xls
Eine andere Frage:
1. Kann man es mit einem Datenfilter versehen und nur die Daten Downloaden, die auch zu sehen sind.
Also nicht die ganze Tabelle updaten.
2. Falls eine Fehlermeldung kommt: xxx Datei konnte nicht gefunden werden, diese dann unterdrücken und weiter mit der nächsten abfrage fortfahren (Bsp., Abbruch bei: LESJ).
Dank dir im Voraus
Gruss
mehmet
Ich habe es inzwischen gemerkt!
Backowe

Hi mehmet,
ich habe jetzt mal selbst die Abfrage eingerichtet und das Gleiche festgestellt! Habe jetzt aber keine Zeit mehr, morgen Mittag geht es weiter. ;o)
Gruß Jürgen
AW: Ich habe es inzwischen gemerkt!
mehmet

OK, txs
Neuer Anlauf!
Backowe

Hi mehmet,
ich habe Dich nicht vergessen! :)
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:L" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
Sheets.Add.Name = "Temp"
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A5").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
    .Columns("B").Delete
  End With
Next
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
Kleine letzte Korrektur!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A100").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
AW: Kleine letzte Korrektur!
mehmet

Hallo Jürgen,
was soll ich sagen, du bist super 8-)
Es funktioniert. Dank dir.
Leider sind die Daten nicht sortiert.
Wie könnte man diese noch sortieren?
Alles was mit ....KT oder .....MPS endet unter Wind/Grad (Punkte stehen für Zahlen, wobei ersten 3 Zahlen für Grad und folgend mit Knoten angegeben werden).
alles was mit ../.. oder ./. oder ../. oder ./.. unter Temperature/Dew Point (Temperatur/TauPunkt)
alles was nachfolgend mit Q... oder Q.... beginnt unter Pressure (Luftdruck)
alles was mit NOSIG unter Remarks Spalte.
Ich weis, dass es bischen kompliziert ist, aber eine Sortierung der Daten währe es toll!
Ist das Möglich?
Als Anhang habe ich die Tabelle2 (bereits downgeloaded) mit der Kopfzeile beschriftet.
https://www.herber.de/bbs/user/54935.xls
Dank im Voraus
Herzliche Grüsse
mehmet
Letztes Posting!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A200").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Sub Sortieren()
Dim Zelle As Range
Application.ScreenUpdating = True
With Sheets("Tabelle1")
  If .FilterMode Then .ShowAllData
  .Range("N2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(RIGHT(F2,2)=""KT"",RIGHT(F2,3)=""MPS"")"
  For Each Zelle In .Range("O2:O" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    If InStr(Zelle.Offset(0, -5), "/") > 0 Then
      Zelle.Value = True
    Else
      Zelle.Value = False
    End If
  Next
  .Range("P2:P" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(Left(K2,1)=""Q"",LEFT(L2,5)=""NOSIG"")"
  'Beim Sortieren gibt es 3 Möglichkeiten, ich habe "Q" und "NOSIG" zusammengefasst, wenn es nicht passen sollte,
  'einfach anpassen!
  .Range("A2:Q" & .Cells(.Rows.Count, "A").End(xlUp).Row).Sort Key1:=.Range("N2"), Order1:=xlDescending, Key2:=.Range("O2") _
    , Order2:=xlDescending, Key3:=.Range("P2"), Order3:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
  .Columns("N:P").Delete shift:=xlLeft
End With
Application.ScreenUpdating = False
End Sub
Gruss Jürgen
AW: Letztes Posting!
mehmet

Hallo Jürgen,
ich danke dir für deine Hilfe
Gruss
mehmet
Anzeige
AW: Kleiner Fehler berichtigt!
25.08.2008 18:57:39
mehmet
Dank dir Jürgen,
beim einlesen werden die anderen Daten überschrieben statt versetzt.
Hier die Datei:
https://www.herber.de/bbs/user/54899.xls
Eine andere Frage:
1. Kann man es mit einem Datenfilter versehen und nur die Daten Downloaden, die auch zu sehen sind.
Also nicht die ganze Tabelle updaten.
2. Falls eine Fehlermeldung kommt: xxx Datei konnte nicht gefunden werden, diese dann unterdrücken und weiter mit der nächsten abfrage fortfahren (Bsp., Abbruch bei: LESJ).
Dank dir im Voraus
Gruss
mehmet
Anzeige
Ich habe es inzwischen gemerkt!
25.08.2008 19:05:00
Backowe
Hi mehmet,
ich habe jetzt mal selbst die Abfrage eingerichtet und das Gleiche festgestellt! Habe jetzt aber keine Zeit mehr, morgen Mittag geht es weiter. ;o)
Gruß Jürgen
AW: Ich habe es inzwischen gemerkt!
25.08.2008 19:21:00
mehmet
OK, txs
Neuer Anlauf!
26.08.2008 15:18:00
Backowe
Hi mehmet,
ich habe Dich nicht vergessen! :)
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:L" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
Sheets.Add.Name = "Temp"
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A5").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
    .Columns("B").Delete
  End With
Next
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
Kleine letzte Korrektur!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A100").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
AW: Kleine letzte Korrektur!
mehmet

Hallo Jürgen,
was soll ich sagen, du bist super 8-)
Es funktioniert. Dank dir.
Leider sind die Daten nicht sortiert.
Wie könnte man diese noch sortieren?
Alles was mit ....KT oder .....MPS endet unter Wind/Grad (Punkte stehen für Zahlen, wobei ersten 3 Zahlen für Grad und folgend mit Knoten angegeben werden).
alles was mit ../.. oder ./. oder ../. oder ./.. unter Temperature/Dew Point (Temperatur/TauPunkt)
alles was nachfolgend mit Q... oder Q.... beginnt unter Pressure (Luftdruck)
alles was mit NOSIG unter Remarks Spalte.
Ich weis, dass es bischen kompliziert ist, aber eine Sortierung der Daten währe es toll!
Ist das Möglich?
Als Anhang habe ich die Tabelle2 (bereits downgeloaded) mit der Kopfzeile beschriftet.
https://www.herber.de/bbs/user/54935.xls
Dank im Voraus
Herzliche Grüsse
mehmet
Letztes Posting!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A200").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Sub Sortieren()
Dim Zelle As Range
Application.ScreenUpdating = True
With Sheets("Tabelle1")
  If .FilterMode Then .ShowAllData
  .Range("N2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(RIGHT(F2,2)=""KT"",RIGHT(F2,3)=""MPS"")"
  For Each Zelle In .Range("O2:O" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    If InStr(Zelle.Offset(0, -5), "/") > 0 Then
      Zelle.Value = True
    Else
      Zelle.Value = False
    End If
  Next
  .Range("P2:P" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(Left(K2,1)=""Q"",LEFT(L2,5)=""NOSIG"")"
  'Beim Sortieren gibt es 3 Möglichkeiten, ich habe "Q" und "NOSIG" zusammengefasst, wenn es nicht passen sollte,
  'einfach anpassen!
  .Range("A2:Q" & .Cells(.Rows.Count, "A").End(xlUp).Row).Sort Key1:=.Range("N2"), Order1:=xlDescending, Key2:=.Range("O2") _
    , Order2:=xlDescending, Key3:=.Range("P2"), Order3:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
  .Columns("N:P").Delete shift:=xlLeft
End With
Application.ScreenUpdating = False
End Sub
Gruss Jürgen
AW: Letztes Posting!
mehmet

Hallo Jürgen,
ich danke dir für deine Hilfe
Gruss
mehmet
Anzeige
Kleine letzte Korrektur!
26.08.2008 16:43:00
Backowe
Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A100").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Gruß Jürgen
AW: Kleine letzte Korrektur!
mehmet

Hallo Jürgen,
was soll ich sagen, du bist super 8-)
Es funktioniert. Dank dir.
Leider sind die Daten nicht sortiert.
Wie könnte man diese noch sortieren?
Alles was mit ....KT oder .....MPS endet unter Wind/Grad (Punkte stehen für Zahlen, wobei ersten 3 Zahlen für Grad und folgend mit Knoten angegeben werden).
alles was mit ../.. oder ./. oder ../. oder ./.. unter Temperature/Dew Point (Temperatur/TauPunkt)
alles was nachfolgend mit Q... oder Q.... beginnt unter Pressure (Luftdruck)
alles was mit NOSIG unter Remarks Spalte.
Ich weis, dass es bischen kompliziert ist, aber eine Sortierung der Daten währe es toll!
Ist das Möglich?
Als Anhang habe ich die Tabelle2 (bereits downgeloaded) mit der Kopfzeile beschriftet.
https://www.herber.de/bbs/user/54935.xls
Dank im Voraus
Herzliche Grüsse
mehmet
Letztes Posting!
Backowe

Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A200").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Sub Sortieren()
Dim Zelle As Range
Application.ScreenUpdating = True
With Sheets("Tabelle1")
  If .FilterMode Then .ShowAllData
  .Range("N2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(RIGHT(F2,2)=""KT"",RIGHT(F2,3)=""MPS"")"
  For Each Zelle In .Range("O2:O" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    If InStr(Zelle.Offset(0, -5), "/") > 0 Then
      Zelle.Value = True
    Else
      Zelle.Value = False
    End If
  Next
  .Range("P2:P" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(Left(K2,1)=""Q"",LEFT(L2,5)=""NOSIG"")"
  'Beim Sortieren gibt es 3 Möglichkeiten, ich habe "Q" und "NOSIG" zusammengefasst, wenn es nicht passen sollte,
  'einfach anpassen!
  .Range("A2:Q" & .Cells(.Rows.Count, "A").End(xlUp).Row).Sort Key1:=.Range("N2"), Order1:=xlDescending, Key2:=.Range("O2") _
    , Order2:=xlDescending, Key3:=.Range("P2"), Order3:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
  .Columns("N:P").Delete shift:=xlLeft
End With
Application.ScreenUpdating = False
End Sub
Gruss Jürgen
AW: Letztes Posting!
mehmet

Hallo Jürgen,
ich danke dir für deine Hilfe
Gruss
mehmet
Anzeige
AW: Kleine letzte Korrektur!
26.08.2008 18:12:53
mehmet
Hallo Jürgen,
was soll ich sagen, du bist super 8-)
Es funktioniert. Dank dir.
Leider sind die Daten nicht sortiert.
Wie könnte man diese noch sortieren?
Alles was mit ....KT oder .....MPS endet unter Wind/Grad (Punkte stehen für Zahlen, wobei ersten 3 Zahlen für Grad und folgend mit Knoten angegeben werden).
alles was mit ../.. oder ./. oder ../. oder ./.. unter Temperature/Dew Point (Temperatur/TauPunkt)
alles was nachfolgend mit Q... oder Q.... beginnt unter Pressure (Luftdruck)
alles was mit NOSIG unter Remarks Spalte.
Ich weis, dass es bischen kompliziert ist, aber eine Sortierung der Daten währe es toll!
Ist das Möglich?
Als Anhang habe ich die Tabelle2 (bereits downgeloaded) mit der Kopfzeile beschriftet.
https://www.herber.de/bbs/user/54935.xls
Dank im Voraus
Herzliche Grüsse
mehmet
Anzeige
Letztes Posting!
26.08.2008 19:53:00
Backowe
Hi mehmet,
VBA-Code:
Sub Einlesen_MitTabMitTxtInSpalte()
Dim Ergebnis As Variant
Dim ImportZeile As String
Dim i As Integer, j As Integer, y As Integer
Application.ScreenUpdating = False
With Sheets("Tabelle1")
  .Range("B2:M" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With
For i = 2 To 1 + Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).SpecialCells(xlCellTypeVisible).Row
  Sheets.Add.Name = "Temp"
  With Sheets("Temp")
    .Cells.NumberFormat = "@"
    Sheets("Tabelle1").Range("A2:A200").SpecialCells(xlCellTypeVisible).Copy _
      Destination:=.Range("A2")
    On Error Resume Next
    .QueryTables.Add(Connection:="URL;ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/" & _
      .Cells(i, "A") & ".TXT", Destination:=.Cells(i, "B")).Refresh BackgroundQuery:=False
    If Err = 0 Then
      ImportZeile = .Cells(i, "B").Value & " " & .Cells(i + 1, "B").Value
      Ergebnis = Split(ImportZeile, " ")
        For j = 0 To UBound(Ergebnis)
          .Cells(i, j + 2) = Ergebnis(j)
        Next
      y = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Range("A1:A" & Sheets("Tabelle1").Cells(Sheets("Tabelle1").Rows.Count, "A").End(xlUp).Row), 0)
      .Range("B" & i & ":M" & i).Copy _
        Destination:=Sheets("Tabelle1").Range("B" & y)
    End If
  End With
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Next
Application.ScreenUpdating = True
End Sub
Sub Sortieren()
Dim Zelle As Range
Application.ScreenUpdating = True
With Sheets("Tabelle1")
  If .FilterMode Then .ShowAllData
  .Range("N2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(RIGHT(F2,2)=""KT"",RIGHT(F2,3)=""MPS"")"
  For Each Zelle In .Range("O2:O" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    If InStr(Zelle.Offset(0, -5), "/") > 0 Then
      Zelle.Value = True
    Else
      Zelle.Value = False
    End If
  Next
  .Range("P2:P" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=OR(Left(K2,1)=""Q"",LEFT(L2,5)=""NOSIG"")"
  'Beim Sortieren gibt es 3 Möglichkeiten, ich habe "Q" und "NOSIG" zusammengefasst, wenn es nicht passen sollte,
  'einfach anpassen!
  .Range("A2:Q" & .Cells(.Rows.Count, "A").End(xlUp).Row).Sort Key1:=.Range("N2"), Order1:=xlDescending, Key2:=.Range("O2") _
    , Order2:=xlDescending, Key3:=.Range("P2"), Order3:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
  .Columns("N:P").Delete shift:=xlLeft
End With
Application.ScreenUpdating = False
End Sub
Gruss Jürgen
AW: Letztes Posting!
mehmet

Hallo Jürgen,
ich danke dir für deine Hilfe
Gruss
mehmet
AW: Letztes Posting!
27.08.2008 07:12:00
mehmet
Hallo Jürgen,
ich danke dir für deine Hilfe
Gruss
mehmet

299 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige