|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 统计结果()
'定义变量
Dim lastRown As Long '最后的行的数值
Dim shtData As Worksheet '数据表
Dim shtResult As Worksheet '结果表
Dim recordColumn As Long '记录日期保存的行数
'赋值
Set shtData = Sheet1
Set shtResult = Sheet2
lastRown = shtData.Cells(Rows.Count, "A").End(xlUp).Row '数据表最后一行的值
'清除结果表的数据
shtResult.Cells.ClearContents
'定义首行
shtResult.Range("A1") = "业务员"
shtResult.Range("B1") = "客户名"
shtResult.Range("C1") = "单据余额"
For irown = 2 To lastRown
'业务员 客户名 单据余额
shtResult.Cells(irown, "A").Value = shtData.Cells(irown, "A").Value
shtResult.Cells(irown, "A").Offset(0, 1).Value = shtData.Cells(irown, "A").Offset(0, 1).Value
shtResult.Cells(irown, "A").Offset(0, 2).Value = shtData.Cells(irown, "A").Offset(0, 2).Value
recordColumn = 4 '保存记录行数
'选出对应 日期的数据
For yColumn = 4 To 34
If shtData.Cells(irown, yColumn).Value <> "" Then
shtResult.Cells(irown, recordColumn).Value = shtData.Cells(1, yColumn).Value
shtResult.Cells(irown, recordColumn).Offset(0, 1).Value = shtData.Cells(irown, yColumn).Value
recordColumn = recordColumn + 2
End If
Next
Next
End Sub
|
|