在多个工作表上将单元格值增加1

我有一个工作簿40张,其中30人有相同的Excel表设置。 我需要一个macros,它将在“月结”列中的表格范围内的30个表格内增加1个单元格。 我已经尝试了在一张纸上工作的以下内容 – 但不确定如何在多张纸上进行相同的工作 – 我也不需要消息框:

Sub MonthIncrease() Dim r1 As Range Dim cell As Range Set r1 = Sheets("Customer 1").Range("Customer1[Months Billed]") For Each cell In r1 If IsNumeric(cell.Value) Then If cell.Value > 0 Then cell.Value = cell.Value + 1 End If Else MsgBox "Cell " & cell.Address(0, 0) & " does not have a number" Exit Sub End If Next End Sub 

我假设那40张中的30张有“客户1”,“客户2”等等的名字。

在这种情况下是这样的

 Option Explicit Sub MonthIncrease() Dim cell As Range Dim i As Long For i = 1 To 30 With Sheets("Customer " & i).Range("Customer1[Months Billed]") For Each cell In .SpecialCells(xlCellTypeConstants, xlNumbers) If cell.Value > 0 Then cell.Value = cell.Value + 1 Next cell End With Next i End Sub 

在那里我也把MsgBox一个脱离了Exit Sub语句

如果你正在search的数字是公式的结果,那就改变了

 .SpecialCells(xlCellTypeConstants, xlNumbers) 

 .SpecialCells(xlCellTypeFormulas, xlNumbers) 
 Sub MonthIncrease() Dim r1 As Range, cell As Range, i As Integer For i = 1 To 30 Set r1 = Sheets(i).Range("Customer1[Months Billed]") For Each cell In r1 If IsNumeric(cell.Value) Then If cell.Value > 0 Then cell.Value = cell.Value + 1 Else MsgBox "Cell " & cell.Address(0, 0) & " does not have a number" Exit Sub End If Next Next i End Sub