macros已停止工作

我妻子在工作中的电子表格已经停止工作。 您将数据input到一个易于使用的工作表上的一个标签上,然后按下一个button,数据将被传输到另一张工作表上。 input选项卡被称为“NCR报告”,下面的表格选项卡被称为“PM2”是macros。 任何想法为什么它停止工作?

Sub Button111_Click() Dim a As Date Dim Counter As Integer Dim Filled As Boolean Dim ParamOut As String Dim i As Integer Dim Reels As String MsgBox ("Wait...") 'Identify 1st empty row Counter = 3 While Filled = False Counter = Counter + 1 a = Worksheets("PM 2").Cells(Counter, 1).Value If a = 0 Then Filled = True Else: Filled = False End If Wend 'Shift Worksheets("PM2").Cells(Counter, 2).Value = Worksheets("NCR Report").Cells(2, 7).Value 'Production date Worksheets("PM2").Cells(Counter, 1).Value = Worksheets("NCR Report").Cells(3, 7).Value 'Article number Worksheets("PM2").Cells(Counter, 4).Value = Worksheets("NCR Report").Cells(4, 7).Value 'Total weight Worksheets("PM2").Cells(Counter, 5).Value = Worksheets("NCR Report").Cells(16, 8).Value 'Parameter out, build the string ParamOut = "" For i = 21 To 24 If Worksheets("NCR Report").Cells(i, 2).Text <> "" Then ParamOut = ParamOut & " " & Worksheets("NCR Report").Cells(i, 2).Text & " " & Worksheets("NCR Report").Cells(i, 5).Text & " " & Worksheets("NCR Report").Cells(i, 9).Text & " " & Worksheets("NCR Report").Cells(i, 10).Text End If Next i Worksheets("PM2").Cells(Counter, 6).Value = ParamOut 'Adjustements Worksheets("PM2").Cells(Counter, 7).Value = Worksheets("NCR Report").Cells(29, 2).Value 'Reel number Reels = "" Reels = Worksheets("NCR Report").Cells(10, 2).Text For i = 11 To 15 If Worksheets("NCR Report").Cells(i, 2).Value = 0 Then Else: Reels = Reels & " / " & Worksheets("NCR Report").Cells(i, 2).Text End If Next i Worksheets("PM2").Cells(Counter, 3).Value = Reels MsgBox ("NCR has been successfully added to the spreadsheet." & vbCrLf & "Don't forget to save this file before quitting and also to block the reels on PLAIN.") End Sub 

你有不一致的工作表名称的引用。 其中一个案例是:

a =工作表(“ PM 2 ”).Cells(Counter,1).Value

后来它的:

工作表(“ PM2 ”).Cells(Counter,2).Value = Worksheets(“NCR Report”)。Cells(2,7).Value

代码需要匹配工作表的实际名称,无论有没有空格