excel的VBA如何让所有工作表都执行当前代码

我有一段代码:
Sub aa()
For i = 3 To 32

If Cells(i, 7).Value = "" Then 'i代表行,1代表列
Cells(i, 7).Value = Cells(i, 6).Value
End If
Next i
End Sub

意思当前工作表中G列中如果为空,则自动等于F列中的值。
现在这个工作薄一共有31个同样的工作表,我想在所有工作表中都实现上面的代码,怎么写?

Sub aa()
 dim sh as worksheet
 for each sh in thisworkbook.sheets
   For i = 3 To 32
   If sh.Cells(i, 7).Value = "" Then 'i代表行,1代表列
      sh.Cells(i, 7).Value = sh.Cells(i, 6).Value
   End If
   Next i
  next
End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-05-22
Sub aa()
    For j = 1 To Worksheets.Count
        With Worksheets(j)
            For i = 3 To 32
                If .Cells(i, 7).Value = "" Then 'i代表行,1代表列
                   .Cells(i, 7).Value = .Cells(i, 6).Value
                End If
            Next
        End With
   Next
End Sub

本回答被网友采纳
第2个回答  2015-09-18
Sub aa()

    Dim Sh As Worksheet

    For Each Sh In Worksheets

        

        For i = 3 To 32

            If Sh.Cells(i, 7).Value = "" Then 'i代表行,1代表列

                Sh.Cells(i, 7).Value = Sh.Cells(i, 6).Value

            End If

        Next i

        

    Next

End Sub

第3个回答  2015-09-18
要在每个表格的VBA中worksheet方法中调用该过程 语句为CALL aa();
但调用肯定您在什么条件下进行调用,要选择合适的worksheet的方法。
相似回答