|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
<P>前一段时间完成了应收账款明细账查询,前提是所有数据都在excel中,用excel做数据库,缺点:速度太慢</P>
<P>Sub LookupAR()<BR>Dim FinalRow As Integer<BR>Dim FinalColumn As Integer<BR>Dim DataBase As Range<BR>Dim FlagRange As Range<BR>Dim MonthRange As Range<BR>Dim AimRange As Range<BR>Dim CriteriaRange As Range<BR>Dim ORange As Range<BR>Dim StartTime<BR>Dim FinishTime</P>
<P>Application.ScreenUpdating = False<BR>StartTime = Timer</P>
<P>'假定明细帐最多2000行</P>
<P><BR>Range(Cells(7, 1), Cells(2006, 20)).Delete<BR>Range("i1:iv1").EntireColumn.Delete<BR>FinalColumn = Range("iv4").End(xlToLeft).Column<BR>Debug.Print FinalColumn<BR>Cells(6, 4) = "上年结转"<BR>Cells(6, 8).Formula = "=if(iserror(VLOOKUP(C2,BeginningAmount,2,FALSE)),0,VLOOKUP(C2,BeginningAmount,2,FALSE))"<BR>Cells(6, 8) = Cells(6, 8).Value<BR>With Worksheets("凭证录入")</P>
<P>Cells(1, FinalColumn + 3).Resize(1, 5) = Array(.Cells(4, 3), .Cells(4, 4), .Cells(4, 5), .Cells(4, 8), .Cells(4, 9))</P>
<P>End With</P>
<P>Set ORange = Cells(1, FinalColumn + 3).Resize(1, 5)</P>
<P>Range("pzlr").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _<BR>"ARCriteria"), CopyToRange:=ORange, Unique:=False<BR>ORange.EntireColumn.Select<BR>Selection.Columns.AutoFit<BR>Selection.Font.Size = 9</P>
<P>'设计本月合计、累计</P>
<P>Dim AimRow As Integer<BR>Dim FlagRow As Integer<BR>Dim FlagColumn As Integer<BR>Dim TotalCreditMonth As Currency<BR>Dim TotalDebitMonth As Currency<BR>Dim TotalCreditYear As Currency<BR>Dim TotalDebitYear As Currency<BR>AimRow = 7: FlagRow = 2: FlagColumn = 11<BR>Do While Cells(FlagRow, FlagColumn) <> ""<BR> TotalDebitYear = TotalDebitYear + Cells(FlagRow, FlagColumn + 3)<BR> TotalCreditYear = TotalCreditYear + Cells(FlagRow, FlagColumn + 4)<BR> <BR> If Cells(FlagRow + 1, FlagColumn) <> "" And Month(Cells(FlagRow, FlagColumn)) <> Month(Cells(FlagRow + 1, FlagColumn)) Then<BR> <BR> <BR> Cells(AimRow, 1) = Month(Cells(FlagRow, FlagColumn))<BR> Cells(AimRow, 2) = Day(Cells(FlagRow, FlagColumn))<BR> Cells(FlagRow, FlagColumn + 1).Resize(1, 4).Copy Destination:=Cells(AimRow, 3)<BR> Cells(AimRow + 1, 3) = "本月合计"<BR> Cells(AimRow + 2, 3) = "累计"<BR> If Cells(AimRow + 1, 3) = "本月合计" Then<BR> Cells(AimRow + 1, 5) = Cells(FlagRow, FlagColumn + 3) + TotalDebitMonth<BR> Cells(AimRow + 1, 6) = Cells(FlagRow, FlagColumn + 4) + TotalCreditMonth<BR> TotalDebitMonth = 0: TotalCreditMonth = 0<BR> Cells(AimRow + 2, 5) = TotalDebitYear<BR> Cells(AimRow + 2, 6) = TotalCreditYear<BR> <BR> End If<BR> <BR> AimRow = AimRow + 2<BR> <BR> <BR> Else<BR> Cells(AimRow, 1) = Month(Cells(FlagRow, FlagColumn))<BR> Cells(AimRow, 2) = Day(Cells(FlagRow, FlagColumn))<BR> Cells(FlagRow, FlagColumn + 1).Resize(1, 4).Copy Destination:=Cells(AimRow, 3)<BR> TotalCreditMonth = TotalCreditMonth + Cells(FlagRow, FlagColumn + 4)<BR> TotalDebitMonth = TotalDebitMonth + Cells(FlagRow, FlagColumn + 3)<BR> <BR> <BR> End If<BR> <BR> AimRow = AimRow + 1<BR> FlagRow = FlagRow + 1<BR>Loop<BR>Cells(AimRow, 3) = "本月合计"<BR>Cells(AimRow + 1, 3) = "累计"<BR>Cells(AimRow, 5) = TotalDebitMonth<BR>Cells(AimRow, 6) = TotalCreditMonth<BR>Cells(AimRow + 1, 5) = TotalDebitYear<BR>Cells(AimRow + 1, 6) = TotalCreditYear<BR>Range("a6").Select<BR>FinalRow = [c65536].End(xlUp).Row<BR>Set region = Range("a6").Resize(FinalRow - 5, 8)<BR>irow = 7<BR>Do While Cells(irow, 3) <> ""<BR> If Cells(irow, 3) = "本月合计" Or Cells(irow, 3) = "累计" Then<BR> Cells(irow, 8).Value = Cells(irow - 1, 8)<BR> <BR> Else<BR> Cells(irow, 8).Value = Cells(irow - 1, 8) + Cells(irow, 5) - Cells(irow, 6)<BR> End If<BR> If Cells(irow, 8).Value > 0 Then<BR> Cells(irow, 7) = "借"<BR> Else<BR> If Cells(irow, 8).Value = 0 Then<BR> Cells(irow, 7) = "平"<BR> Else<BR> Cells(irow, 7) = "贷"<BR> End If<BR> End If<BR> <BR> irow = irow + 1<BR>Loop<BR> region.RowHeight = 15<BR> <BR> With region<BR> .HorizontalAlignment = xlLeft<BR> .VerticalAlignment = xlBottom<BR> .WrapText = False<BR> .Orientation = 0<BR> .AddIndent = False<BR> .IndentLevel = 0<BR> .ShrinkToFit = False<BR> .ReadingOrder = xlContext<BR> .MergeCells = False<BR> End With<BR> region.Borders(xlDiagonalDown).LineStyle = xlNone<BR> region.Borders(xlDiagonalUp).LineStyle = xlNone<BR> With region.Borders(xlEdgeLeft)<BR> .LineStyle = xlContinuous<BR> .Weight = xlThin<BR> .ColorIndex = 5<BR> End With<BR> With region.Borders(xlEdgeTop)<BR> .LineStyle = xlContinuous<BR> .Weight = xlThin<BR> .ColorIndex = 5<BR> End With<BR> With region.Borders(xlEdgeBottom)<BR> .LineStyle = xlContinuous<BR> .Weight = xlThin<BR> .ColorIndex = 5<BR> End With<BR> With region.Borders(xlEdgeRight)<BR> .LineStyle = xlContinuous<BR> .Weight = xlThin<BR> .ColorIndex = 5<BR> End With<BR> With region.Borders(xlInsideVertical)<BR> .LineStyle = xlContinuous<BR> .Weight = xlThin<BR> .ColorIndex = 5<BR> End With<BR> With region.Borders(xlInsideHorizontal)<BR> .LineStyle = xlContinuous<BR> .Weight = xlThin<BR> .ColorIndex = 5<BR> End With<BR> <BR>'返回程序运行时间<BR>FinishTime = Timer<BR>MsgBox "应收账款----" & Cells(2, 3).Value & Chr(13) & Chr(10) & "明细帐查询共用了:" & Chr(13) & Chr(10) & FinishTime - StartTime & "秒"<BR>Application.ScreenUpdating = True</P>
<P>region.Columns("h").NumberFormatLocal = "#,##0.00_ "<BR>Range("k1:iv1").EntireColumn.Delete<BR>End Sub</P> |
|