怎么用excel VBA range 函数来表示

怎么用excel VBA range 函数来表示
Cells(j, "J") = xlsheet.Cells(i, "E")
Cells(j, "K") = xlsheet.Cells(i, "F")
Cells(j, "L") = xlsheet.Cells(i, "G")
Cells(j, "M") = xlsheet.Cells(i, "H")
Cells(j, "N") = xlsheet.Cells(i, "I")
Cells(j, "O") = xlsheet.Cells(i, "J")
Cells(j, "P") = xlsheet.Cells(i, "K")
Cells(j, "Q") = xlsheet.Cells(i, "L")
Cells(j, "R") = xlsheet.Cells(i, "M")
Cells(j, "S") = xlsheet.Cells(i, "N")
谢谢了

其他代码如下:
Private Sub CommandButton1_Click()
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlbook = xlApp.Workbooks.Open("D:\EXCEL\ITS电气元器件库.xlsm")
xlApp.Visible = False
Set xlsheet = xlbook.Worksheets("sheet1")
Dim i As Integer, j As Integer, h As Integer, k As Integer, l As Integer, m As Integer, n As Integer
k = 0
l = 0
m = WorksheetFunction.CountA(Workbooks("ITS电气元器件库.xlsm").Sheets("sheet1").range("d:d"))
n = WorksheetFunction.CountA(range("d:d"))
range("j3:s300").ClearContents
For i = 3 To m
For j = 3 To n
If (InStr(1, Cells(j, 4), xlsheet.Cells(i, 4), vbTextCompare) > 0 Or InStr(1, Cells(j, 7), xlsheet.Cells(i, 4), vbTextCompare) > 0) And Not Cells(j, 4) = "" And Not xlsheet.Cells(i, 4) = "" Then
Cells(j, "J") = xlsheet.Cells(i, "E")
Cells(j, "K") = xlsheet.Cells(i, "F")
Cells(j, "L") = xlsheet.Cells(i, "G")
Cells(j, "M") = xlsheet.Cells(i, "H")
Cells(j, "N") = xlsheet.Cells(i, "I")
Cells(j, "O") = xlsheet.Cells(i, "J")
Cells(j, "P") = xlsheet.Cells(i, "K")
Cells(j, "Q") = xlsheet.Cells(i, "L")
Cells(j, "R") = xlsheet.Cells(i, "M")
Cells(j, "S") = xlsheet.Cells(i, "N")
If xlsheet.Cells(i, 3) = Cells(j, 5) Then

range("j"&j)
range("k"&j)
、、、、
括号里是双引号里为列标,后面加个连接符号&和变量名称j追问

range("j"&j)里j是代表行标吗

追答

前面的"J"是指J列的列标,因为range表示区域时,里面要加双引号的,比如 用range("a1:c1")来表示A1:C1区域,里面的字母不区分大小写,range("A1:C1")也是一样的
后面的j是指你定义的变量,代表行数,如果你定义了for j=1 to 10,那么range("j"&j)就是 J1、J2、J3、、、、、J10,循环到10之后就停止了。
range("j"&j)--range("j"&1)--range("j1")
range("j"&j)--range("j"&2)--range("j2")
里面的&连接符是把J列标和变量1、2、3给连接起来

温馨提示:内容为网友见解,仅供参考
第1个回答  2015-05-29
xlsheet.Range("E" & i &":N" & i).Copy Cells(j, "J")追问

我按照 这样做了,运行后提示:类range的copy方法无效

追答

不会哟,那换一个方式试试:
Cells(j, "J").resize(,10).value = xlsheet.Cells(i, "E").resize(,10).value

相似回答