我在使用VB6构建报告时遇到了一些问题。基本上,我正在构建一个动态报告,其中标题和2列(客户端,学生)从记录集中填充。正如您在图片中看到的,在我的标题末尾,我添加了一个TOTAL标题,下面有客户和学生。我试图让每个专栏中的所有客户总数达到TOTAL,与学生一样。列数(UCLA,SDU,SCCU)可能会有所不同,所以我试图让它变成动态的。基本上从A开始,然后是B,然后是C,D和NONE。有任何想法吗? 编辑:我请从SQL SERVER的SHORT LABEL和填充直到g_RS3是空Excel报告 - 公式VBA
Do While Not g_RS3.EOF
With xlSheet.Cells(xlRow, xlCol)
.Value = g_RS3("ShortLabel")
.Offset(1, 0).Value = " Clients "
.Offset(1, 1).Value = " Students"
With .Offset(1, 0)
.Font.Bold = True
.Borders.Weight = xlThin
End With
With .Offset(1, 1)
.Font.Bold = True
.Borders.Weight = xlThin
End With
With .Resize(1, 2)
.Font.Bold = True
.WrapText = True
.VerticalAlignment = xlCenter
.Merge
.HorizontalAlignment = xlCenter
.Borders.Weight = xlThin
End With
End With
xlCol = xlCol + 2
g_RS3.MoveNext
Loop
With xlSheet.Cells(xlRow, xlCol)
.Value = "TOTAL"
.Offset(1, 0).Value = "Clients"
.Offset(1, 1).Value = "Students"
With .Offset(1, 0)
.Font.Bold = True
.Borders.Weight = xlThin
End With
With .Offset(1, 1)
.Font.Bold = True
.Borders.Weight = xlThin
End With
With .Resize(1, 2)
.Font.Bold = True
.WrapText = True
.VerticalAlignment = xlCenter
.Merge
.HorizontalAlignment = xlCenter
.Borders.Weight = xlThin
End With
End With
然后我开始xlrow = 4 xlcol = 2和填充数据在客户端和STUDENT列。我拥有的循环相当长。但用户只会查看摘录。一旦它的产生取决于他们,他们用它做什么。该应用程序为他们提供了添加SHORTLABEL的选项,一旦它们生成,SHORTLABEL需要在提取中显示。
哪一个VBA或VB6? – 0m3r
[SUMIFS函数](https://support.office.com/en-us/article/SUMIFS-function-C9E748F5-7EA7-455D-9406-611CEBCE642B)将执行此操作;例如'= sumifs($ b4:$ g4,$ b $ 3:$ g $ 3,$ h $ 3)''。如果必须在VBA中执行计算或[Range.Formula属性](https:/ /),请使用[WorksheetFunction对象](https://msdn.microsoft.com/en-us/library/office/ff834434.aspx) /msdn.microsoft.com/en-us/library/office/ff838835.aspx)如果你想保留公式。 – Jeeped
顺便说一句,你将不得不决定是否使用'CLIENT'或'CLIENTS'。不应该有一个标准的多个版本。 – Jeeped