2013-10-23 73 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

相關問題