下面的代码,根据今天的日期(日期已经手动写在A列中)找到合适的行,并在同一行插入数据。我需要将最后一个结果(今天的日期)添加到名为“图表”的不同工作表上的柱形图中。
Sub Worksheets_Summary()
Dim OldSheet As Worksheet
Dim NewSheet As Worksheet
Dim Cell As Range
Dim ColNum As Integer
Dim RwNum As Long
Dim book As Workbook
Set book = ThisWorkbook
Set NewSheet = book.Worksheets("Summary")
RwNum = NewSheet.Columns(1).Find(Date).Row
ColNum = 1
For Each OldSheet In book.Worksheets
If OldSheet.Name <> "Summary" Then
ColNum = ColNum + 1
NewSheet.Cells(1, ColNum).Formula _
= "=HYPERLINK(""#""&CELL(""address"",'" & OldSheet.Name & "'!A1)," _
& """" & OldSheet.Name & """)"
NewSheet.Cells(RwNum, ColNum).Value = OldSheet.Range("B11").Value
End If
Next OldSheet
NewSheet.UsedRange.Columns.AutoFit
End Sub
注意:图表中仅显示新结果。
这是代码运行后的摘要工作表: 摘要表
这是代码运行后的仪表板工作表: 仪表板表