本帖最后由 wp231957 于 2020-5-26 18:35 编辑
把这个代码添加,应该就可以解决闪屏的问题了,至于什么是闪屏,知者自知Application.ScreenUpdating = False '关闭屏幕更新
关于区域复制 粘贴,剪切 等操作Sub wp()
Range("a1:b5").Select
Set bs = Selection
bs.Copy
Range("a6:b" & Range("A65536").End(xlUp).Row).Select
Set bs2 = Selection
bs2.Cut
Range("A1").Select
ActiveSheet.Paste
End Sub
传说中的公历转农历函数,实测就是闰月会有些问题
=TEXT(F3,"[$-130000]YYYY-M-D")
判断平年闰年的(农历)=IF(TEXT(2020+1 &"-2","[$-130000]m")="13","闰年","平年")
在两个工作簿之间切换,获取当前工作簿的名字 Sub wp()
Application.DisplayAlerts = False '退出excel 不抛出提示框,当然改动也不会存盘
Application.ScreenUpdating = False '关闭屏幕更新
Dim wkb As Workbook
Set wkb = Workbooks.Add
wkb.SaveAs Filename:="d:\123.xlsx"
Windows(ThisWorkbook.Name).Activate
Range("a1:b5").Copy
Windows("123.xlsx").Activate
Sheets(1).Range("a1").Select
ActiveSheet.Paste
Windows(ThisWorkbook.Name).Activate
end_row = Range("A65536").End(xlUp).Row
If end_row > 5 Then
Range("a1:b5").Clear
Range("a6:b" & end_row).Select
Set bs2 = Selection
bs2.Cut
Range("A1").Select
ActiveSheet.Paste
Else
Range("a1:b5").Clear
End If
wkb.Save
wkb.Close
End Sub
获取合并单元格所占用的行数 MsgBox Range("a4").MergeArea.Rows.Count
如果有合并单元格,以下为真正的占行数
Sub test()
tmp = Range("A65536").End(xlUp).Row
arr = Range("a4:a" & tmp)
Debug.Print UBound(arr) + Range("a" & tmp).MergeArea.Rows.Count - 1
End Sub
vba中使用excel函数SUMIF应用Sub wp()
srxm = Range("a4").MergeArea.Rows.Count
Range("j4") = WorksheetFunction.SumIf(Range("e4:e" & srxm - 1), "现金", Range("h4:h" & srxm - 1))
Range("k4") = WorksheetFunction.SumIf(Range("e4:e" & srxm - 1), "建行", Range("h4:h" & srxm - 1))
Range("l4") = WorksheetFunction.SumIf(Range("e4:e" & srxm - 1), "公户", Range("h4:h" & srxm - 1))
Range("r4") = WorksheetFunction.SumIf(Range("m4:m" & srxm - 1), "现金", Range("p4:p" & srxm - 1))
Range("s4") = WorksheetFunction.SumIf(Range("m4:m" & srxm - 1), "建行", Range("p4:p" & srxm - 1))
Range("t4") = WorksheetFunction.SumIf(Range("m4:m" & srxm - 1), "公户", Range("p4:p" & srxm - 1))
End Sub
vba中使用excel函数COUNTBLANK应用Sub test()
Range("k1:k22").Select
tmp = 1
For i = 1 To Selection.Rows.Count
If WorksheetFunction.CountBlank(Range("k" & i)) = 0 Then
Range("l" & i) = WorksheetFunction.CountBlank(Range("k" & tmp & ":" & "k" & i))
tmp = i
End If
Next
End Sub
vba条件隐藏行Sub a()
Dim rg As Range
Application.ScreenUpdating = False
Sheets("sheet1").Range("g3:g56").Select
For Each rg In Selection
If rg.Value = "null" Or rg.Value = "" Then
rg.EntireRow.Hidden = True
End If
Next rg
Application.ScreenUpdating = True
End Sub
|