各位大神請幫幫忙,謝謝
大神您好,不知道怎麼回事,只抓取第一列的資料......
如果下圖符合你要的結果
(顏色區域為 VBA 填入資料, 無色區域需預先輸入資料/公式)
VBA 程式如下
自己隨意改
Sub Main()
Dim nLastRow, nRow As Integer
Range("A1").Select
Selection.End(xlDown).Select
nLastRow = ActiveCell.Row
'Newest day
nRow = nLastRow
If nRow > 1 Then
Range("H1").Value = Cells(nRow, 1).Value
Range("H2").Value = Cells(nRow, 2).Value
Range("H3").Value = Cells(nRow, 3).Value
Range("H4").Value = Cells(nRow, 4).Value
Range("H5").Value = Cells(nRow, 5).Value
Else
Exit Sub
End If
'Previous day
nRow = nLastRow - 1
If nRow > 1 Then
Range("I1").Value = Cells(nRow, 1).Value
Range("I2").Value = Cells(nRow, 2).Value
Range("I3").Value = Cells(nRow, 3).Value
Range("I4").Value = Cells(nRow, 4).Value
Range("I5").Value = Cells(nRow, 5).Value
Else
Exit Sub
End If
'7 days ago
nRow = nLastRow - 7
If nRow > 1 Then
Range("J2").Value = Cells(nRow, 2).Value
Range("J3").Value = Cells(nRow, 3).Value
Range("J4").Value = Cells(nRow, 4).Value
Range("J5").Value = Cells(nRow, 5).Value
Else
Exit Sub
End If
'30 days ago
nRow = nLastRow - 30
If nRow > 1 Then
Range("L2").Value = Cells(nRow, 2).Value
Range("L3").Value = Cells(nRow, 3).Value
Range("L4").Value = Cells(nRow, 4).Value
Range("L5").Value = Cells(nRow, 5).Value
Else
Exit Sub
End If
'365 days ago
nRow = nLastRow - 365
If nRow > 1 Then
Range("N2").Value = Cells(nRow, 2).Value
Range("N3").Value = Cells(nRow, 3).Value
Range("N4").Value = Cells(nRow, 4).Value
Range("N5").Value = Cells(nRow, 5).Value
Else
Exit Sub
End If
End Sub