|
楼主 |
发表于 2014-8-31 09:24
|
显示全部楼层
本帖最后由 lqg2069 于 2014-8-31 09:30 编辑
lipton 发表于 2014-8-29 09:43
Globals.ThisWorkbook.Sheets(1).Range("A3:A10")
表示工作表集合的第一张表(不管是什么表),某天用户 ...
以上是简化的语句。我用excel取得WCF服务的数据,放在临时表qtbb,然后用excel二次汇总数据,下面是我的原代码。
Private Sub Sheet2_ActivateEvent() Handles Me.ActivateEvent
Globals.ThisWorkbook.Application.ScreenUpdating = False
With Globals.ThisWorkbook.Sheets("地区商品")
Globals.ThisWorkbook.Application.StatusBar = "正在汇总 地区商品,请稍等。。"
.range("b1") = Globals.ThisWorkbook.Sheets("报表").Range("b1").Text & Year(Now()) & "年" & Month(Now()) & "月" & Globals.ThisWorkbook.Sheets("报表").Range("f1").Text & "汇总进.销.存报表"
Dim z As Integer = .UsedRange.Rows.Count
If z > 6 Then .Rows("4:" & z - 2 & "").Delete()
Dim z3 As Integer = Globals.ThisWorkbook.Sheets("qtbb").UsedRange.Rows.Count
z = Globals.ThisWorkbook.Sheets("报表").Range("G1").Value2
If z > 0 Then
.Rows("4:" & z + 3 & "").Insert()
.Range("A4:d" & z + 4 & "").value = Globals.ThisWorkbook.Sheets("qtbb").Range("B3:E" & z + 2 & "").value
Dim BB As Integer = .UsedRange.Rows.Count
.Range("A4:C" & BB - 2 & "").NumberFormatLocal = "@"
.Range("E4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C[1])"
.Range("F4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C[1])"
.Range("G4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C[9])-SUMIF(qtbb!C2,地区商品!RC1,qtbb!C[10])"
.Range("H4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("I4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C[9])-SUMIF(qtbb!C2,地区商品!RC1,qtbb!C[10])"
.Range("J4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("K4").FormulaR1C1 = "=RC[-4]+RC[-2]"
.Range("L4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("M4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C10)"
.Range("N4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("O4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C11)"
.Range("P4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("Q4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C12)"
.Range("R4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C13)"
.Range("S4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C14)"
.Range("T4").FormulaR1C1 = "=RC[-3]+RC[-2]+RC[-1]"
.Range("U4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("V4").FormulaR1C1 = "=RC[-9]+RC[-7]+RC[-2]"
.Range("W4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("X4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C15)"
.Range("Y4").FormulaR1C1 = "=RC[-1]*RC4"
.Range("Z4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C20)"
.Range("AA4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C21)"
.Range("AB4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C22)"
.Range("AC4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C23)"
.Range("AD4").FormulaR1C1 = "=SUMIF(qtbb!C2,地区商品!RC1,qtbb!C24)"
.Range("AE4").FormulaR1C1 = "=RC[-7]+RC[-5]-RC[-4]+RC[-3]+RC[-2]-RC[-1]"
.Range("AF4").FormulaR1C1 = "=RC[-27]+RC[-21]-RC[-10]-RC[-8]+RC[-6]-RC[-5]+RC[-4]+RC[-3]-RC[-2]"
.Range("E4:AF4").AutoFill(Destination:=.Range("E4:AF" & BB - 2 & ""))
.Range("E" & BB - 1 & ":AF" & BB - 1 & "").FormulaR1C1 = "=SUM(R[-" & BB - 5 & "]C:R[-1]C)"
.Range("e4:af" & BB - 1 & "").value = .Range("e4:af" & BB - 1 & "").value
If .Range("AF" & BB - 1 & "").Value <> 0 Then Globals.ThisWorkbook.Sheets("报表").Range("o2") = "报表不平!" Else Globals.ThisWorkbook.Sheets("报表").Range("o2") = ""
Dim wsth As Integer = Me.Application.WorksheetFunction.Sum(Globals.ThisWorkbook.Sheets("qtbb").Range("y3:y" & z3 & ""))
Dim bs As Integer = Me.Application.WorksheetFunction.Sum(Globals.ThisWorkbook.Sheets(1).Range("z3:z" & z3 & ""))
Dim zc As Integer = Me.Application.WorksheetFunction.Sum(Globals.ThisWorkbook.Sheets("qtbb").Range("aa3:aa" & z3 & ""))
Dim jh As Integer = Me.Application.WorksheetFunction.Sum(Globals.ThisWorkbook.Sheets("qtbb").Range("ab3:ab" & z3 & ""))
Dim dh As Integer = Me.Application.WorksheetFunction.Sum(Globals.ThisWorkbook.Sheets("qtbb").Range("ac3:ac" & z3 & ""))
Dim th As Integer = Me.Application.WorksheetFunction.Sum(Globals.ThisWorkbook.Sheets("qtbb").Range("ad3:ad" & z3 & ""))
If System.Math.Abs(wsth) + System.Math.Abs(bs) + System.Math.Abs(zc) + System.Math.Abs(jh) + System.Math.Abs(dh) + System.Math.Abs(th) = 0 Then
Globals.ThisWorkbook.Sheets("报表").Range("p2") = ""
Else
Globals.ThisWorkbook.Sheets("报表").Range("p2") = "未审(退货" & wsth & "报损" & bs & "支出" & zc & "),未收(进货" & jh & "调货" & dh & "退货" & th
End If
End If
End With
Globals.ThisWorkbook.Application.StatusBar = False
Globals.ThisWorkbook.Application.ScreenUpdating = True
End Sub
|
|