Excel2003,怎样写代码来实现把数字填写到指定的位置,谢谢!

2025-03-28 06:27:41
推荐回答(2个)
回答(1):

在工作表标签上点击鼠标右键选查看代码,粘贴以下代码到右侧窗口,保存,

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Not Intersect(Target, Range("C2:G529")) Is Nothing Then
    If IsNumeric(Target.Value) Then
        Dim arr(1 To 11) As Integer
        For Each rng In Range("C" & Target.Row).Resize(1, 5)
                arr(rng.Value) = rng.Value
                Cells(Target.Row, 9).Resize(1, 11) = arr
        Next
    Else
        MsgBox Target.Address(0, 0) & "单元格,输入的不是数字!请重新输入!"
    End If
End If
End Sub

回答(2):

Sub Refresh()
Dim i, j As Integer
For i = 2 To 529
Cells(i, 8 + Cells(i, 3)) = Cells(i, 3)
Cells(i, 8 + Cells(i, 4)) = Cells(i, 4)
Cells(i, 8 + Cells(i, 5)) = Cells(i, 5)
Cells(i, 8 + Cells(i, 6)) = Cells(i, 6)
Cells(i, 8 + Cells(i, 7)) = Cells(i, 7)
For j = 9 To 19
If Cells(i, j) = "" Then
Cells(i, j) = 0
End If
Next j
Next i
End Sub