2013-10-23 51 views
1

我想跨我的工作簿中的多个数据表运行此宏,但我不能让代码跨工作簿正常运行。如果我在单张纸上运行宏,它可以正常运行,但我现在试图运行所有纸张,并排除“数据”和“更新”表,并且如果有任何关于如何解决的问题,通过所有工作表正常运行?由于运行宏多个工作表排除

Sub UpdatePrices() 
    Dim ws As Worksheet, Ldate As String, DateRng As Range 
    Set DateRng = Range("A3") 'date range is last date 
    Ldate = DateRng.Value 'defines ldate as most recent date 

    For Each ws In ActiveWorkbook.Worksheets 

'Inserts a new row with containing today's Date and exclude sheets 
    If Ldate <> Date And ws.Name <> "DATA" Or ws.Name <> "UPDATE" Then 
    DateRng.EntireRow.Insert 
    DateRng.Offset(-1, 0) = "=TODAY()" 
    Else 
    End If 
    Next ws 
    End sub 

回答

0

试试下面的代码

Sub UpdatePrices() 
    Dim ws As Worksheet, Ldate As String, DateRng As Range 
    Set DateRng = Sheets("Sheet1").Range("A3") 'date range is last date 
    Ldate = DateRng.Value 'defines ldate as most recent date 

    For Each ws In ThisWorkbook.Worksheets 
     ws.Select 
     'Inserts a new row with containing today's Date and exclude sheets 
     If Ldate <> Date And UCase(ws.Name) <> "DATA" And UCase(ws.Name) <> "UPDATE" Then 
      ws.Rows(DateRng.Row).EntireRow.Insert 
      ws.Cells(DateRng.Row, DateRng.Column).Offset(-1, 0) = "=TODAY()" 
     End If 

    Next 

End Sub 
+0

这个工作谢谢 – Nrandazzo

相关问题