0
到目前爲止,我有一個宏來查找一年,並將其複製到新工作表。不過,我可能要多年。我的數據集的結構如下:複製inputbox指示的多個範圍
Col A Col B Col C Col D ColE
Year Week Amount time forecast
2000 1 368 2000w1 400
2000 2 8646 2000w2 8500
until...
2014 52 46546 2014w52 47000
到現在爲止,我的宏:下面
Sub Copyyear()
Dim Forecastyear As String
Dim Rng As Range
Dim cell As Range
Forecastyear = InputBox("Enter a year to forecast")
If Trim(Forecastyear) <> "" Then
With Sheets(2)
For Each cell In .Range("A:A")
If cell.Value = Forecastyear Then 'find first occurrence of year
Set Rng = cell
Exit For
End If
Next
'.Range(Rng.Address).Resize(52, 5).Select 'resize for 52 rows and 5 columns
Rng.Resize(52, 5).Copy Destination:=Sheets("Moving Average").Range("A2")
End With
End If
' Record in new sheet
Worksheets("Moving Average").Select
Range("A1").Value = "YEAR"
Range("B1").Value = "WEEK"
Range("C1").Value = "AMOUNT"
Range("D1").Value = "TIME"
Range("E1").Value = "FORECAST"
' next macro
AddForecastPerformance
End Sub
你想要一張表嗎?或者你想複製粘貼一切 – Hearner