我的想法是我有一個工作簿表中的名稱列表。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,所以我知道這個代碼是醜陋,但它的工作原理笑!只需尋求幫助就可以解決問題,從而減少手動更新名稱和動態。
嘗試查看我是否理解正確.......您希望有人能夠將工作表(工作表b)添加到工作簿並讓代碼遍歷每行。每次在單獨的工作表(工作表a)上找到該名稱,它將搜索(工作表a)中的名稱,並將公式應用到名稱被找到的(工作表a)中的行。 – ShanayL