
我想做的是,首先我有一個包含大量資料的 CSV 檔案。
第一列 A 的日期和時間以空格分隔,如 03/11/2017 12:55:34。
我想選擇兩個日期之間的儲存格,例如之間的範圍03/11/2017 12:55:34
到03/11/2017 15:55:34
,然後使用文字到列分隔選取範圍的日期和時間,最後繪製分隔時間及其對應值的圖表。
該程式碼工作正常,無需進行文字到列的轉換。但我不知道選擇範圍後如何進行文字到列的轉換。
我特此附上程式碼。
Function getData()
Dim findrow As Long, findrow2 As Long
Dim dataTable As Range
findrow = Range("A:B").Find("3/13/2017 15:49:57.108", Range("A1")).Row
findrow2 = Range("A:B").Find("3/13/2017 16:04:57.098", Range("A" & findrow)).Row
Set dataTable = Range("A" & findrow + 1 & ":B" & findrow2 - 1)
Set getData = dataTable
End Function
Sub SelectBetween()
Dim rng As Range
Dim cht As Object
'Your data range for the chart
Set rng = getData()
rng.Select
'Create a chart
Set cht = ActiveSheet.Shapes.AddChart2
'Give chart some data
cht.Chart.SetSourceData Source:=rng
'Determine the chart type
cht.Chart.ChartType = xlLine
cht.Chart.ChartTitle.Text = Cells(1, 1).Value
cht.Chart.SetElement (msoElementLegendBottom)
cht.Chart.SeriesCollection(1).Name = "=""CPU Processor Time"""
cht.Chart.Axes(xlValue).MinimumScale = 0
cht.Chart.Axes(xlValue).MaximumScale = 100
End Sub