2012-08-04 32 views
-1

鏈接到示例工作簿:http://www.wikisend.com/download/245286/MIS%20-%20July%20%20(1).xlsmVBA碼通過迭代紙張和特定的數據複製到特定細胞

工作簿具有刪除所有sheeets VBA代碼,然後創建由從其他工作簿複印張新表。

我想要另一個vba代碼自動生成包含所有格式和數據的執行摘要表。一些公式沒有很好的定義,所以他們必須稍後手動編輯。至於其他工作表witll改變每一個月手動參考WUD是乏味

我當前的代碼:

Sub WorksheetLoop() 

     Sheets.Add After:=Sheets(Sheets.Count) 
     Sheets(Sheets.Count).Select 
     Sheets(Sheets.Count).Name = "Executive Summary" 


     Sheets("Executive Summary").Select 
'Some formatting code on sheet Executive Summary 

    Dim ws As Worksheet 
     ' Begin the loop. 
currentRow=6 'start entering data from row 6 
    For Each ws In ThisWorkbook.Worksheets 

'Assign cell at row=current row and col B reference to cell G5 at sheet ws 
'Assign cell at row=current row and col F reference to cell J15 at sheet ws 

'Assign cell at row=current row and col H reference to cell T5 at sheet ws 


'increment Current row by 1 
    'don't know what to do here  
    Next ws 

'select entire region(all filled cells) 
'format text, add border etc 

    End Sub 

請告訴我引用的語法

+0

什麼阻止你使用直線公式?另外,不是每次都銷燬表單,然後用公式和表示重新構建表單,爲什麼不把它留在那裏並刪除內容?我認爲你正在推翻這項任務。也許你應該發佈一個示例工作簿,以便我們可以更好地回答你的問題。 – ApplePie 2012-08-04 11:01:30

+0

如何添加示例工作表 – user1568701 2012-08-04 12:30:59

+0

您可以上傳到wikisend.com並在此共享鏈接? – 2012-08-05 01:00:39

回答

0

問題解決了

Sub test() 

    Sheets("Executive Summary").Select 
    Range("A6:P23").Select 
    Range("P6").Activate 
    Selection.ClearContents 
    'Dim ws As Worksheet 
    Dim Row As Integer 
    Row = 6 
    For Each ws In ThisWorkbook.Worksheets 
    If ws.Name <> "Executive Summary" Then 
     Range("A" & Row).Value = "='" & ws.Name & "'!C3" 
     Range("B" & Row).Value = "='" & ws.Name & "'!G5" 
     Range("C" & Row).Value = "='" & ws.Name & "'!G39" 
     Range("D" & Row).Value = "='" & ws.Name & "'!H39" 
     Range("E" & Row).Value = "=D" & Row & "-C" & Row 
     Range("F" & Row).Value = "=IF(A" & Row & "=" & Chr(34) & "POWER" & Chr(34) & ",+E" & Row & "*B" & Row & ",+E" & Row & "*B" & Row & "/100)" 
     Range("G" & Row).Value = "=IF(A" & Row & "=" & Chr(34) & "POWER" & Chr(34) & ",+(J" & Row & "-D" & Row & ")*B" & Row & ",+(J" & Row & "-D" & Row & ")*B" & Row & "/100)" 
     '"=(J" & Row & "-D" & Row & ")*B" & Row & "/100" 
     Range("H" & Row).Value = "=I" & Row & "-F" & Row & "-G" & Row 
     Range("I" & Row).Value = 0 
     Range("J" & Row).Value = "='" & ws.Name & "'!I39" 
     Range("K" & Row).Value = "='" & ws.Name & "'!L5" 
     Range("L" & Row).Value = "='" & ws.Name & "'!K39" 
     Range("M" & Row).Value = "=G" & Row 
     Range("N" & Row).Value = "=O" & Row & "-L" & Row & "-M" & Row 
     Range("O" & Row).Value = "=I" & Row 
     Range("P" & Row).Value = "='" & ws.Name & "'!M39" 
     Row = Row + 1 
    End If 

    Next ws 

End Sub 
相關問題