我的想法是我有一个工作簿表中的名称列表。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