2017-08-24 22 views
0

我的想法是我有一個工作簿表中的名稱列表。VBA從更改列表中填充摘要表

此列表可能會隨時更新到時候添加新的隊友。然後我在另一張紙上有彙總表。

我需要的是當列表得到更新時,此列表將填充彙總表的列A,然後如果名稱位於彙總表的A行的行內,則還可以在其他列上應用公式。

任何幫助,將不勝感激!

現在,我把它手動添加名稱列A的每一行,然後尋找其他工作表的名稱等我最終設法讓這個而不是通過代碼手動添加名稱,不熟悉VBA的人可以將名稱添加到列表下的其他表格中,然後使用拉來生成列表,然後讓代碼搜索這些名稱並應用正確的公式。

任何幫助將是偉大的!這裏是我現在的代碼,但我希望我可以包括我在開始時提到的內容(帶有一張名單從那裏拉出並可以更新的表單)。此代碼的工作,但需要的人,如果添加了新隊友更新代碼...

Sub Summary() 
    'Summary table Team 
    Application.ScreenUpdating = False 
    Dim sheet As Worksheet 

ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count) 
ActiveSheet.name = "Summary" 

'Making the Table 
ActiveSheet.Range(Cells(1, "A"), Cells(13, "G")).Borders.LineStyle = xlContinuous 

Cells(1, "A").Value = "Header 1" 
Cells(1, "B").Value = "Header 2" 
Cells(1, "C").Value = "header 3" 
Cells(1, "D").Value = "header 4" 
Cells(1, "E").Value = "header 5" 
Cells(1, "F").Value = "header 6" 
Cells(1, "G").Value = "header 7" 

Cells(2, "A").Value = "John" 
Cells(3, "A").Value = "Bob" 
Cells(4, "A").Value = "Laura" 
Cells(5, "A").Value = "Linda" 
Cells(6, "A").Value = "Lucy" 
Cells(7, "A").Value = "Alice" 
Cells(8, "A").Value = "Margret" 
Cells(9, "A").Value = "Matt" 
Cells(10, "A").Value = "Steve" 
Cells(11, "A").Value = "Tim" 
Cells(12, "A").Value = "Luke" 
Cells(13, "A").Value = "Tara" 

Range("A1:I1").EntireColumn.AutoFit 

'Adding the Formulas for the Table 

Worksheets("Summary").Activate 

ActiveSheet.Range("B2:B13").Formula = "=COUNTIFS('Sheet1'!G:G,Summary!A2)" 
ActiveSheet.Range("C2:C13").Formula = "=COUNTIFS('Sheet2'!G:G,Summary!A2)" 
ActiveSheet.Range("D2:D13").Formula = "=COUNTIFS('Sheet3'!G:G,Summary!A2)" 
ActiveSheet.Range("E2:E13").Formula = "=COUNTIFS('Sheet4'!G:G,Summary!A2)" 
ActiveSheet.Range("F2:F13").Formula = "=COUNTIFS('Sheet5'!G:G,Summary!A2)" 
ActiveSheet.Range("G2:G13").Formula = "=COUNTIFS('Sheet6'!G:G,Summary!A2)" 

'Adding conditional formatting 
    Range("B2:G13").Select 
Selection.formatconditions.Add Type:=xlCellValue, Operator:=xlEqual, _ 
    Formula1:="=0" 
Selection.formatconditions(Selection.formatconditions.Count).SetFirstPriority 
With Selection.formatconditions(1).Font 
    .Color = -16752384 
    .TintAndShade = 0 
End With 
With Selection.formatconditions(1).Interior 
    .PatternColorIndex = xlAutomatic 
    .Color = 13561798 
    .TintAndShade = 0 
End With 
Selection.formatconditions(1).StopIfTrue = False 
Selection.formatconditions.Add Type:=xlCellValue, Operator:=xlGreater, _ 
    Formula1:="=0" 
Selection.formatconditions(Selection.formatconditions.Count).SetFirstPriority 
With Selection.formatconditions(1).Font 
    .Color = -16383844 
    .TintAndShade = 0 
End With 
With Selection.formatconditions(1).Interior 
    .PatternColorIndex = xlAutomatic 
    .Color = 13551615 
    .TintAndShade = 0 
End With 
Selection.formatconditions(1).StopIfTrue = False 

Application.ScreenUpdating = True 
End Sub 

還相當新的VBA,所以我知道這個代碼是醜陋,但它的工作原理笑!只需尋求幫助就可以解決問題,從而減少手動更新名稱和動態。

+0

嘗試查看我是否理解正確.......您希望有人能夠將工作表(工作表b)添加到工作簿並讓代碼遍歷每行。每次在單獨的工作表(工作表a)上找到該名稱,它將搜索(工作表a)中的名稱,並將公式應用到名稱被找到的(工作表a)中的行。 – ShanayL

回答

0

我承認你的努力解決在使用VBA這個問題,但我堅信你是過於複雜的事情。 Excel的核心功能更適合以比使用自定義VBA代碼更快,更高效的方式解決您的問題。

解決您的問題,創建一個動態命名的區域來保存你的名字的列表。這種方式在將來需要添加名稱時會自動添加到整個工作簿中。在功能區中,單擊公式,名稱管理器,添加(我打電話給我的名字「,並假設你的名字的名單都在列A在Sheet1:

=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),1) 

要在其他工作表上使用的名稱,只需使用=names

在問候式上另一片,我會用佔位符。例如,你在你的總結表的B列使用=COUNTIFS('Sheet1'!G:G,Summary!A2)。您的公式填充B列,但在添加IF聲明前面。因此,這將成爲=IF($A2=0,"",COUNTIFS('Sheet1'!G:G,Summary!A2)),這將沒有名字的空白讓行。

無需VBA即可像平常一樣添加格式。

現在,您可以通過添加一個名字測試,一切都將更新。讓我知道你是否需要任何額外的幫助。