excel vba编码,想将Sheet1中的内容筛选到Sheet2中,但一直报错“下标越界”。代码如下: 10

Sub筛选()Dima%,b%,c%,i%,j%,r%Dimarr1()AsString,arr2()AsStringb=Sheets("Sheet1").[F65536... Sub 筛选()
Dim a%, b%, c%, i%, j%, r%
Dim arr1() As String, arr2() As String
b = Sheets("Sheet1").[F65536].End(xlUp).Row
c = Application.WorksheetFunction.CountIf(Sheets(1).Range("F2:F" & b), "<=7") - Application.WorksheetFunction.CountIf(Sheets(1).Range("F2:F" & b), "<=0")
ReDim arr1(1 To c) As String, arr2(1 To c) As String
i = 1
j = 1
For r = 2 To c + 1
For a = 2 To b
If Cells(a, 6).Value <= 7 And Cells(a, 6).Value > 0 Then
arr1(i) = Left(Sheets(1).Range("A" & a), 50) & "@genomics.cn"
arr2(j) = Left(Sheets(1).Range("B" & a), 50) & "@genomics.cn"
Sheets(2).Cells(r, 1).Value = arr1(i)
Sheets(2).Cells(r, 2).Value = arr2(j)
End If
i = i + 1
j = j + 1
Next
Next
End Sub
展开
 我来答
hwjljf
2014-11-03 · TA获得超过217个赞
知道小有建树答主
回答量:388
采纳率:100%
帮助的人:220万
展开全部
我想你是数组定义错误,数组的下标应该是0开始的,请试试:
Sub 筛选()
Dim a%, b%, c%, i%, j%, r%
Dim arr1() As String, arr2() As String
b = Sheets("Sheet1").[F65536].End(xlUp).Row
c = Application.WorksheetFunction.CountIf(Sheets(1).Range("F2:F" & b), "<=7") - Application.WorksheetFunction.CountIf(Sheets(1).Range("F2:F" & b), "<=0")
ReDim arr1(0 To c-1) As String, arr2(0 To c-1) As String
i = 0
j = 0
For r = 2 To c+1
For a = 2 To b
If Cells(a, 6).Value <= 7 And Cells(a, 6).Value > 0 Then
arr1(i) = Left(Sheets(1).Range("A" & a), 50) & "@genomics.cn"
arr2(j) = Left(Sheets(1).Range("B" & a), 50) & "@genomics.cn"
Sheets(2).Cells(r, 1).Value = arr1(i)
Sheets(2).Cells(r, 2).Value = arr2(j)
End If
i = i + 1
j = j + 1
Next
Next
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式