我已经写了一个宏来从一张纸到另一张纸上获取一些excel数据,以便我可以根据条件轻松使用数据
Sub page(rowNumber As Integer)
Dim row_number As Integer
Dim iterator As Integer
Dim srch_string As String ' Searching for the string view
Dim IdMethod As String
Dim UIValues As String
Dim Name As String
Dim SheetName As String
Dim number As Integer
Dim result As String
result = " "
IdMethod = " "
UIValues = " "
row_number = rowNumber
iterator = row_number
Name = ActiveWorkbook.FullName
srch_string = "onclick"
number = 3
SheetName = "page"
Application.Worksheets(SheetName).Activate
'while i= rowNumber
Do While iterator > 0
If srch_string = Worksheets(SheetName).Cells(iterator, 5) Then
Exit Do
Else
IdMethod = IdMethod & ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 4)
UIValues = UIValues & ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5)
For Index = 2 To Worksheets("param").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5) = ActiveWorkbook.Worksheets("param").Cells(Index, 1) Then
Do While munber > 0
If result <> srch_string Then
Exit Do
Else
result = ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5)
ActiveWorkbook.Worksheets("param").Cells(number, 1) = ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5)
number = number + 1
iterator = iterator - 1
End If
End If
iterator = iterator - 1
End If
Loop
End Sub
但是如果没有阻止,宏表示结束... 我不确定所有的语法 但是所有的ifs都被正确放置,因为我知道无法弄清楚出了什么问题
答案 0 :(得分:3)
Sub page(rowNumber As Integer)
Dim row_number As Integer
Dim iterator As Integer
Dim srch_string As String ' Searching for the string view
Dim IdMethod As String
Dim UIValues As String
Dim Name As String
Dim SheetName As String
Dim number As Integer
Dim result As String
result = " "
IdMethod = " "
UIValues = " "
row_number = rowNumber
iterator = row_number
Name = ActiveWorkbook.FullName
srch_string = "onclick"
number = 3
SheetName = "page"
Application.Worksheets(SheetName).Activate
'while i= rowNumber
Do While iterator > 0
If srch_string = Worksheets(SheetName).Cells(iterator, 5) Then
Exit Do
Else
IdMethod = IdMethod & ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 4)
UIValues = UIValues & ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5)
For Index = 2 To Worksheets("param").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5) = ActiveWorkbook.Worksheets("param").Cells(Index, 1) Then
Do While munber > 0
If result <> srch_string Then
Exit Do
Else
result = ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5)
ActiveWorkbook.Worksheets("param").Cells(number, 1) = ActiveWorkbook.Worksheets(SheetName).Cells(iterator, 5)
number = number + 1
iterator = iterator - 1
End If
Next '<- Add Next Here (Missing in your code)
End If
Next '<- Add Next Here (Missing in your code)
iterator = iterator - 1
End If
Loop
End Sub
答案 1 :(得分:1)
您缺少关闭的下一个索引
For Index = 2 To Worksheets("param").UsedRange.Rows.Count
修改强>
正如@simoco和@brain指出的那样,你还需要关闭Do While nunber&gt; 0与Loop
。