真的希望有人能帮助我。所以我有以下代码。独立代码本身可以很好地工作,但是在执行脚本时,它只能通过第一个条件循环。我希望它做的是每次循环遍历所有的代码。我认为这是我错过的一件小事,但我似乎无法找到解决方案。sub不会循环通过第二条语句vba
Sub Copypre()
Dim i As Integer
Dim n As Integer
For i = 2 To 10
'Checks the number of entries in the "Pre" table, to make sure that there are no spaces between the lines
On Error Resume Next
n = Worksheets("Pre").Range("A2:A6000").Cells.SpecialCells(xlCellTypeConstants).Count
If n = Null Then
n = i
'Goes through the different sheets to find all "pre" values and paste them in the "Pre" sheet
If ThisWorkbook.Sheets("273").Range("A" & i).Value = "Pre" Then
Range(Cells(i, 1), Cells(i, 3)).Select
Selection.Copy
Sheets("Pre").Select
Range("A" & n).Select
ActiveSheet.Paste
Sheets("2736").Select
End If
End If
Next i
End Sub
目前尚不清楚源工作表是否被命名为* 273 *或* 2736 *。 – Jeeped 2014-09-20 21:15:32
很难弄清楚你的问题是什么,但是你肯定有一些错误的代码,如果'n = null'。 'n'被定义为一个整数,不能为空。你应该改变你的测试为'If n = 0'。也许这会解决你的问题。 – DeanOC 2014-09-20 21:16:56
你如何从一张纸到另一张纸(如果这是你想要的)? – pnuts 2014-09-20 21:18:54