我正在尝试编写一个脚本,将从网页表中提取每小时的值到excel中

表格是15分钟的时间间隔,但我只需要每小时的值。 有没有办法告诉vba只读取时间戳为HH的值:00:00?

Sub GetWaterLevels() Dim URL As String Dim qt As QueryTable Dim ws As Worksheet Set ws = ActiveSheet 'Clears previously loaded data ActiveSheet.Range("C4:D85").ClearContents URL = "http://waterdata.quinteconservation.ca/KiWIS/KiWIS?service=kisters&type=queryServices&request=getTimeseriesValues&datasource=0&format=html&ts_id=3641042&metadata=true&md_returnfields=station_name,ts_name,ts_unitname&&period=PT10H&width=600&height=400" 'Downloads the table into excel Set qt = ws.QueryTables.Add( _ Connection:="URL;" & URL, _ Destination:=Range("C4")) With qt .RefreshOnFileOpen = False .Name = "WaterLevels" .FieldNames = True .WebSelectionType = xlAllTables .Refresh BackgroundQuery:=False End With End Sub 

我每天都会学到新的东西。 你拿到桌子的方式非常快。 我的技能不像你的技能那么好,但是你有下面的难题是我能想出的唯一答案。 我不知道你是否可以在导入端使用你的方法select某些行。 我看着webtables的财产,但不够了解它。 我要做的就是用下面的代码剔除表格。 当我使用你的代码导入表时,它会把第10行上的活动数据放在第10行。你可能需要调整以适应你的需要。

 Sub sortTable() Dim lastRow As Long, firstRow As Long, myArray1, myArray2, myCounter As Long, i As Long ' When I ran your getWaterLevels script it put the data starting on row 10 firstRow = 10 lastRow = ActiveSheet.Range("C65536").End(xlUp).Row myCounter = 1 ReDim myArray1(1 To 1) ReDim myArray2(1 To 1) Application.ScreenUpdating = False For i = firstRow To lastRow If Range("C" & i).Value <> "" And InStr(1, Range("C" & i).Value, ":00:00.") > 0 Then ReDim Preserve myArray1(1 To myCounter) ReDim Preserve myArray2(1 To myCounter) myArray1(myCounter) = Range("C" & i) myArray2(myCounter) = Range("D" & i) myCounter = myCounter + 1 End If Next i Cells.Select With Selection .Font.Name = "Arial" .Font.Size = 11 .Interior.Pattern = xlNone .Interior.TintAndShade = 0 .Interior.PatternTintAndShade = 0 End With Range("C10:D" & lastRow).Select Selection.ClearContents Range("A1").Select myCounter = 10 For i = LBound(myArray1) To UBound(myArray1) Range("C" & myCounter).Value = myArray1(i) Range("D" & myCounter).Value = myArray2(i) myCounter = myCounter + 1 Next i Application.ScreenUpdating = True End Sub