- 5
- 0
- 约 11页
- 2018-06-10 发布于湖南
- 举报
使用listcolumnork处理databodyrange和total8属性
e800,国内最具活力的IT门户网站。 HYPERLINK
【e800编译】此示例演示在Microsoft Excel 2010中如何使用ListColum对象的DataBodyRange和Total属性。
此代码段是Office 2010的101项VBA代码示例中的一部分。与其它示例一样,这些将可以直接写入您的代码中。
每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA或VB以及C#中(在Visual Studio 2010中创建)。每个示例之中都会包含代码以及相应注释,这样您就可以直接运行获取预期的结果,或者是根据代码注释提示来调整环境,运行示例代码。
Microsoft Office 2010提供了你所需要的工具来创建功能强大的应用程序。Microsoft Visual Basic Application(VBA)代码示例可以帮助你创建自己的应用程序,以执行特定功能或者以此为出发点实现更为复杂的功能。
实例代码
在Excel 2010中新建一个工作簿,将下列代码复制到Sheet1类模块,并将光标放在ListColumnDemo,然后按F8执行调试,然后按住Shift+ F8单步执行代码。并列放置VBA和Excel窗口,这样你就可以边运行边查看结果。
Sub ListColumnDemo()
Step over this procedure. Its not terribly interesting.
FillRandomData
Set up the list object.
Dim lo As ListObject
Set lo = ListObjects.Add( _
SourceType:=xlSrcRange, _
Source:=Range(A1:F13), _
XlListObjectHasHeaders:=xlYes)
lo.Name = SampleData
lo.ShowTotals = True
Retrieve a reference to the second column in the ListObject:
Dim lc As ListColumn
Set lc = lo.ListColumns(2)
Retrieve a reference to the ListColumns data, excluding
headers and footers.
Dim rng As Range
Set rng = lc.DataBodyRange
Do some things with the data body range:
rng.Borders.Color = vbRed
rng.FormatConditions.AddDatabar
Retrieve the total for the column and
display it in the totals row.
Obviously, there are other ways to do this:
Dim totalValue As Long
totalValue = WorksheetFunction.Sum(rng)
You should verify that the Total property isnt
Nothing--it will be, if the list object isnt
displaying its totals row. In this case, the totals
row is definitely visible, so this check is extraneous.
If Not lc.Total Is Nothing Then
lc.Total.Value = totalValue
End If
End Sub
Sub FillRandomData()
No need to stop through this procedure.
Range(A1, F1).Value = Array(Month, North, South, East, West, Total)
Fill in twelve rows with random data.
Dim i As Integer
Dim j As Integer
For i = 1 To 12
Cells(i + 1, 1).Value = MonthName(i, True)
For j = 2 To 5
Cells(i + 1, j) = Round(Rnd * 100)
Next j
Next i
Range(F2, F13).Formula = =
您可能关注的文档
最近下载
- 22G101 三维彩色立体图集.docx VIP
- 旅游景区质量等级划分与评价细则.doc VIP
- 深度解析(2026)《ISO 277992016 Health informatics — Information security management in health using ISOIEC 27002》(20标准解读.pptx VIP
- 大学生创新与创业基础教程(大学生创新创业教育课程)全套教学课件.pptx
- 22G101图集下载的文档.pptx VIP
- 《大学生创新创业教育(第三版)微课版》全套教学课件.pptx
- 中国集装箱行业十四五发展分析及投资前景与战略规划研究报告2025-2028版.docx VIP
- gnss全球导航卫星系统.pptx VIP
- 重庆市2026年高二(上)期末联合检测(康德卷)数学+答案.pdf VIP
- 2025年11月26日达州兴川能源有限公司国家电投川东北高效清洁煤电综合利用一体化项目21000MW新建燃煤机组配套500kV升压站工程.pdf VIP
原创力文档

文档评论(0)