码迷,mamicode.com
首页 > 编程语言 > 详细

[VBA]简单的修改Excel表

时间:2016-09-11 22:56:44      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

 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 Long
10     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 row
14         For j = 1 To col
15             arr(i, j) = (i * j) Mod 20
16         Next
17     Next
18     
19     需要选中
20     Worksheets("Sheet3").Activate
21     Dim rng As Variant
22     Set rng = Sheets(3).Range(Cells(1, 1), Cells(row, col))
23     Set rng = Sheets(2).Range("A1:Z26")
24     rng.Value = arr
25 End Sub

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

[VBA]简单的修改Excel表

标签:

原文地址:http://www.cnblogs.com/BoostQt/p/5863030.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!