首页 > 代码库 > [VBA]简单的修改Excel表

[VBA]简单的修改Excel表

 1 Option Explicit 2 Option Base 1 3  4 Sub FillSheet() 5     Dim i As Long 6     Dim j As Long 7     Dim col As Long 8     Dim row As Long 9     Dim arr() As Long10     row = Application.InputBox(prompt:="input row:", Type:=2)11     col = Application.InputBox(prompt:="input column:", Type:=2)12     ReDim arr(row, col)13     For i = 1 To row14         For j = 1 To col15             arr(i, j) = (i * j) Mod 2016         Next17     Next18     19     需要选中20     Worksheets("Sheet3").Activate21     Dim rng As Variant22     Set rng = Sheets(3).Range(Cells(1, 1), Cells(row, col))23     Set rng = Sheets(2).Range("A1:Z26")24     rng.Value =http://www.mamicode.com/ arr25 End Sub

初试VBA,主要注意修改前需要激活对应的sheet,否则报错!

[VBA]简单的修改Excel表